k4iS"zdZddlmZmZmZmZmZmZmZm Z m Z m Z m Z m Z ddlmZddlmZddlmZGddeZy) zJob creation/editing dialog) QDialog QVBoxLayout QHBoxLayout QFormLayout QLineEdit QComboBox QPushButton QTextEditQSpinBox QFileDialog QMessageBox QGroupBox)Qt)DatabaseManager)datetimecFeZdZdZdfd ZdZdZdZdZfdZ xZ S) JobDialogz Dialog for creating/editing jobsct||t|_||_|du|_|j |j rdnd|jd|j|j r|jyy)z Initialize dialog. Args: parent: Parent widget job_id: If provided, edit mode. If None, create mode. NzEdit JobzNew JobiX) super__init__rdbjob_id is_edit_modesetWindowTitlesetMinimumWidth_init_ui_load_job_data)selfparentr __class__s gui/job_dialog.pyrzJobDialog.__init__sy  !# "$. $*;*;JK S!        ! c t}|j|td}t}t |_|j d|j t|_|jjddg|j d|jt}t |_ td}|jj|j|j!|j|j!||j d|t}t |_td}|jj|j$|j!|j"|j!||j d|t'|_|j(j+d d |j(j-d |j(j/d |j d |j(t1|_|j2j5d|j d|j2|j||j!|td}t} t |_|j6j9d| j d|j6t1} | j;d| j5d| j=d| j | |j| |j!|t} | j?td} | jj|j@| j!| td} | jj|jB| j!| |jE| y)zCreate UI layoutz Job DetailszName:script python_modulezType:u 📁 Browsez Executable:z Working Dir:iQiz secondszTimeout:Pz Description:zSchedule (Cron Expression)ze.g., 0 2 * * * (daily at 2 AM)zCron:TdzCron Format: minute hour day month day_of_week Examples: * * * * * - Every minute 0 * * * * - Every hour 0 2 * * * - Daily at 2 AM 0 0 * * 0 - Weekly on Sunday 0 0 1 * * - Monthly on 1stu 💾 Saveu ❌ CancelN)#r setLayoutrrr name_editaddRowr type_comboaddItemsr exec_editr clickedconnect_browse_executable addWidget workdir_edit_browse_workdirr timeout_spinsetRangesetValue setSuffixr description_editsetMaximumHeight cron_editsetPlaceholderText setReadOnly setPlainText addStretchacceptreject addLayout)rlayout details_groupdetails_layout exec_layoutexec_browse_btnworkdir_layoutworkdir_browse_btnschedule_groupschedule_layout helper_text button_layoutsave_btn cancel_btns r!rzJobDialog._init_ui&s# v"-0 $"gt~~6#+   (O!<=gt7"m "%m4''(?(?@dnn-o.m[9%%K(7""**4+?+?@  !2!23  !34nn=$J ""1e, ""4( ##J/j$*;*;< )  ..r2nd.C.CD/'##?@%-" ))*KLw7 k %$$S)   0  {+  1($   "{+  -) . ""4;;/ +'r"cvtj|ddd\}}|r|jj|yy)zBrowse for executable filezSelect Executablez All Files (*)N)r getOpenFileNamer.setText)r file_path_s r!r1zJobDialog._browse_executable}s>"22      1  NN " "9 - r"cltj|d}|r|jj|yy)zBrowse for working directoryzSelect Working DirectoryN)r getExistingDirectoryr3rS)rdir_paths r!r4zJobDialog._browse_workdirs633  &      % %h / r"c|jj5}|j}|jd|jf|j }|jd|jf|j }ddd|j jd|jj|d|jj|d|jj|dxsd|jj|d |jj|d xsdr|j j|d yy#1swYxYw) z"Load existing job data for editingzSELECT * FROM jobs WHERE id = ?zt SELECT cron_expression FROM schedules WHERE job_id = ? AND enabled = 1 Nnamejob_typeexecutable_pathworking_directoryrQtimeout descriptioncron_expression)rget_connectioncursorexecuterfetchoner*rSr,setCurrentTextr.r3r5r7r9r>r;)rconnrbjobschedules r!rzJobDialog._load_job_datas: WW # # % )[[]F NN2 **3}+=+CD  NN " "8,=#> ? ' ) )s A+E,,E5c |jjjstj|ddy|j jjstj|ddy t jj}|jj5}|j}|jr|jd|jjj|jj|j jj|j jjxsd|j"j%|j&j)jxsd||j*f|j*}n|jd|jjj|jj|j jj|j jjxsd|j"j%|j&j)jxsd||f|j,}|j.jj}|r)|jd|f|jd||||fdddt0|ey#1swYxYw#t4$r$}tj6|d d |Yd}~yd}~wwxYw) zValidate and save jobzValidation ErrorzJob name is required.NzExecutable path is required.a UPDATE jobs SET name = ?, job_type = ?, executable_path = ?, working_directory = ?, timeout = ?, description = ?, updated_at = ? WHERE id = ? a INSERT INTO jobs ( name, job_type, executable_path, working_directory, timeout, enabled, description, created_at, updated_at ) VALUES (?, ?, ?, ?, ?, 1, ?, ?, ?) z&DELETE FROM schedules WHERE job_id = ?z INSERT INTO schedules ( job_id, cron_expression, enabled, created_at, updated_at ) VALUES (?, ?, 1, ?, ?) ErrorzFailed to save job: )r*textstripr warningr.rnow isoformatrrarbrrcr, currentTextr3r5valuer9 toPlainTextr lastrowidr;rr@ Exceptioncritical)rrnrfrbr cron_exprer s r!r@zJobDialog.accepts~~""$**,   &8:Q R ~~""$**,   &8:X Y @ L,,.**,C'')8 8T$$NN $++-335335++-335))..0668@D))//1--99;AACKt  ("[[FNN$ ++-335335++-335))..0668@D))//1--99;AACKt  $--F!NN//1779 NN#KfYWNN$!)S#6 8i8 8t GN u8 88 8x L  w2Fqc0J K K Ls1'M >MM M7M22M7)NN) __name__ __module__ __qualname____doc__rrr1r4rr@ __classcell__)r s@r!rr s0*",U(n .0@0LLLLr"rN)r{PyQt6.QtWidgetsrrrrrrr r r r r r PyQt6.QtCorercorerrrr"r!rs7!  hLhLr"