def get_checkin(my): '''the button which initiates the checkin''' # create the button with the javascript function widget = Widget() #button = TextBtnWdg(label=my.PUBLISH_BUTTON, size='large', width='100', side_padding='20', vert_offset='-5') #button.get_top_el().add_class('smaller') button = ActionButtonWdg(title=my.PUBLISH_BUTTON, tip='Publish the selected assets') button.add_style('margin-bottom: 10px') #button.add_color("background", "background") hidden = HiddenWdg(my.PUBLISH_BUTTON, '') button.add( hidden ) ''' status_sel = SelectWdg('checkin_status', label='Status: ') status_sel.set_option('setting', 'checkin_status') status_sel.set_persist_on_submit() status_sel.add_empty_option('-- Checkin Status --') widget.add(status_sel) ''' widget.add(button) # custom defined server_cbk = "pyasm.prod.web.AssetCheckinCbk" #TODO: make other Publish Buttons call their own handle_input function exec( Common.get_import_from_class_path(server_cbk) ) exec( "%s.handle_input(button, my.search_type, my.texture_search_type)" % server_cbk) return widget
def get_save_button(my,checkin_keys): save_button = ActionButtonWdg(title="Save >>", tip="Save configuration and start using TACTIC") save_button.add_style("float: right") save_button.add_behavior( { 'type': 'click_up', 'os' : os.name, 'checkin_options':checkin_keys, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_db_config_top"); var failed_els = top.getElements('.spt_input_validation_failed') if (failed_els.length > 0){ spt.alert('One of the fields fail validation. Please correct it before saving') return; } spt.app_busy.show("Saving configuration. Please wait...") var values = spt.api.Utility.get_input_values(top, null, false); var class_name = 'tactic.ui.startup.DbConfigSaveCbk'; var server = TacticServerStub.get(); var kwargs = {checkin_options:bvr.checkin_options}; try { var ret_val = server.execute_cmd(class_name, kwargs, values); var info = ret_val.info; } catch(e) { log.critical(spt.exception.handler(e)); //FIXME: recognize it's a 502 which is normal and pass , otherwise throw the error //spt.error(spt.exception.handler(e)); //spt.app_busy.hide(); //return; } // This means TACTIC was restarted if (typeof(info) == 'undefined' || bvr.os == 'nt' ) { spt.app_busy.show("Restarting TACTIC ..."); var id = setInterval( function() { var ping_rtn = server.ping(); if (ping_rtn) { window.location = '/tactic'; clearInterval(id); } }, 5000 ); } else if (info.error) { spt.alert(info.error); spt.app_busy.hide(); } else { window.location = '/tactic'; } ''' } ) return save_button
def handle_python_script_test(self, top): top.add(DivWdg('Python Script Test', css='spt_info_title')) table = Table(css='script') table.add_color("color", "color") table.add_style("margin: 10px") table.add_style("width: 100%") top.add(table) table.add_row() td = table.add_cell("Script Path: ") td.add_style("width: 150px") text = TextWdg('script_path') td = table.add_cell(text) button = ActionButtonWdg(title='Run') table.add_cell(button) button.add_style("float: right") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var s = TacticServerStub.get(); try { var path = bvr.src_el.getParent('.script').getElement('.spt_input').value; if (! path) throw('Please enter a valid script path'); s.execute_cmd('tactic.command.PythonCmd', {script_path: path}); } catch(e) { spt.alert(spt.exception.handler(e)); } ''' })
def handle_python_script_test(self, top): top.add(DivWdg('Python Script Test', css='spt_info_title')) table = Table(css='script') table.add_color("color", "color") table.add_style("margin: 10px") table.add_style("width: 100%") top.add(table) table.add_row() td = table.add_cell("Script Path: ") td.add_style("width: 150px") text = TextWdg('script_path') td = table.add_cell(text) button = ActionButtonWdg(title='Run') table.add_cell(button) button.add_style("float: right") button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var s = TacticServerStub.get(); try { var path = bvr.src_el.getParent('.script').getElement('.spt_input').value; if (! path) throw('Please enter a valid script path'); s.execute_cmd('tactic.command.PythonCmd', {script_path: path}); } catch(e) { spt.alert(spt.exception.handler(e)); } ''' })
def get_checkin(my): '''the button which initiates the checkin''' # create the button with the javascript function widget = Widget() #button = TextBtnWdg(label=my.PUBLISH_BUTTON, size='large', width='100', side_padding='20', vert_offset='-5') #button.get_top_el().add_class('smaller') button = ActionButtonWdg(title=my.PUBLISH_BUTTON, tip='Publish the selected assets') button.add_style('margin-bottom: 10px') #button.add_color("background", "background") hidden = HiddenWdg(my.PUBLISH_BUTTON, '') button.add(hidden) ''' status_sel = SelectWdg('checkin_status', label='Status: ') status_sel.set_option('setting', 'checkin_status') status_sel.set_persist_on_submit() status_sel.add_empty_option('-- Checkin Status --') widget.add(status_sel) ''' widget.add(button) # custom defined server_cbk = "pyasm.prod.web.AssetCheckinCbk" #TODO: make other Publish Buttons call their own handle_input function exec(Common.get_import_from_class_path(server_cbk)) exec( "%s.handle_input(button, my.search_type, my.texture_search_type)" % server_cbk) return widget
def get_save_button(my, checkin_keys): save_button = ActionButtonWdg( title="Save >>", tip="Save configuration and start using TACTIC") save_button.add_style("float: right") save_button.add_behavior({ 'type': 'click_up', 'os': os.name, 'checkin_options': checkin_keys, 'cbjs_action': ''' spt.app_busy.show("Saving configuration. Please wait...") var top = bvr.src_el.getParent(".spt_db_config_top"); var values = spt.api.Utility.get_input_values(top, null, false); var class_name = 'tactic.ui.startup.DbConfigSaveCbk'; var server = TacticServerStub.get(); var kwargs = {checkin_options:bvr.checkin_options}; try { var ret_val = server.execute_cmd(class_name, kwargs, values); var info = ret_val.info; } catch(e) { log.critical(spt.exception.handler(e)); //FIXME: recognize it's a 502 which is normal and pass , otherwise throw the error //spt.error(spt.exception.handler(e)); //spt.app_busy.hide(); //return; } // This means TACTIC was restarted if (typeof(info) == 'undefined' || bvr.os == 'nt' ) { spt.app_busy.show("Restarting TACTIC ..."); var id = setInterval( function() { var ping_rtn = server.ping(); if (ping_rtn) { window.location = '/tactic'; clearInterval(id); } }, 5000 ); } else if (info.error) { spt.alert(info.error); spt.app_busy.hide(); } else { window.location = '/tactic'; } ''' }) return save_button
def get_error_wdg(my): div = DivWdg() error_div = DivWdg() error_div.add("Error %s" % my.status) div.add(error_div) error_div.add_style("font-size: 16px") error_div.add_style("font-weight: bold") error_div.add_style("width: 97%") error_div.add_gradient("background", "background") error_div.add_border() error_div.add_style("margin-left: 5px") error_div.add_style("margin-top: -10px") div.add("<br/>") span = DivWdg() #span.add_color("color", "color") span.add_style("color", "#FFF") if my.status == 404: span.add( HtmlElement.b( "You have tried to access a url that is not recognized.")) else: span.add(HtmlElement.b(my.message)) span.add(HtmlElement.br(2)) web = WebContainer.get_web() root = web.get_site_root() if my.message.startswith('No project ['): label = 'You may need to correct the default_project setting in the TACTIC config.' else: label = "Go to the Main page for a list of valid projects" span.add(label) div.add(span) div.add(HtmlElement.br()) from tactic.ui.widget import ActionButtonWdg button = ActionButtonWdg(title="Go to Main", tip='Click to go to main page') div.add(button) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' document.location = '/tactic'; ''' }) button.add_event("onmouseup", "document.location='/tactic'") button.add_style("margin-left: auto") button.add_style("margin-right: auto") return div
def get_error_wdg(my): div = DivWdg() error_div = DivWdg() error_div.add("Error %s" % my.status) div.add(error_div) error_div.add_style("font-size: 16px") error_div.add_style("font-weight: bold") error_div.add_style("width: 97%") error_div.add_gradient("background", "background") error_div.add_border() error_div.add_style("margin-left: 5px") error_div.add_style("margin-top: -10px") div.add("<br/>") span = DivWdg() # span.add_color("color", "color") span.add_style("color", "#FFF") if my.status == 404: span.add(HtmlElement.b("You have tried to access a url that is not recognized.")) else: span.add(HtmlElement.b(my.message)) span.add(HtmlElement.br(2)) web = WebContainer.get_web() root = web.get_site_root() if my.message.startswith("No project ["): label = "You may need to correct the default_project setting in the TACTIC config." else: label = "Go to the Main page for a list of valid projects" span.add(label) div.add(span) div.add(HtmlElement.br()) from tactic.ui.widget import ActionButtonWdg button = ActionButtonWdg(title="Go to Main", tip="Click to go to main page") div.add(button) button.add_behavior( { "type": "click_up", "cbjs_action": """ document.location = '/tactic'; """, } ) button.add_event("onmouseup", "document.location='/tactic'") button.add_style("margin-left: auto") button.add_style("margin-right: auto") return div
def get_search_wdg(my): filter_div = DivWdg() filter_div.add_style("width: 200px") search_button = ActionButtonWdg(title='Search', tip='Run search with this criteria') if my.run_search_bvr: run_search_bvr = my.run_search_bvr else: # cbjs works better than cbfn here run_search_bvr = { 'type': 'click_up', 'new_search': True, 'cbjs_action': 'spt.dg_table.search_cbk(evt, bvr)', 'panel_id': my.prefix, } search_button.add_behavior(run_search_bvr) # add a listener for other widgets to call Run Search listen_bvr = run_search_bvr.copy() listen_bvr['type'] = 'listen' listen_bvr['event_name'] = 'search_%s' % my.search_type # needed for CgApp loader search_button.add_behavior(listen_bvr) clear_button = ActionButtonWdg(title='Clear', tip='Clear all search criteria') clear_button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.api.Utility.clear_inputs(bvr.src_el.getParent(".spt_search"), '.spt_input:not(select.spt_search_filter_mode)'); ''' }) # {'label': 'Clear', 'tip': 'Clear all search criteria', 'width': 45, # 'bvr': {'cbjs_action': 'spt.api.Utility.clear_inputs(bvr.src_el.getParent(".spt_search"))'} } #] #txt_btn_set = TextBtnSetWdg(buttons=buttons_list, spacing=6, size='small', side_padding=4 ) filter_div.add(search_button) search_button.add_style("float: left") filter_div.add(clear_button) clear_button.add_style("float: left") filter_div.add("<br clear='all'/>") return filter_div
def get_search_wdg(my): filter_div = DivWdg() filter_div.add_style("width: 200px") search_button = ActionButtonWdg(title='Search', tip='Run search with this criteria') if my.run_search_bvr: run_search_bvr = my.run_search_bvr else: # cbjs works better than cbfn here run_search_bvr = { 'type': 'click_up', 'new_search': True, 'cbjs_action': 'spt.dg_table.search_cbk(evt, bvr)', 'panel_id': my.prefix, } search_button.add_behavior( run_search_bvr ) # add a listener for other widgets to call Run Search listen_bvr = run_search_bvr.copy() listen_bvr['type'] = 'listen' listen_bvr['event_name'] = 'search_%s' %my.search_type # needed for CgApp loader search_button.add_behavior( listen_bvr ) clear_button = ActionButtonWdg(title='Clear', tip='Clear all search criteria') clear_button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.api.Utility.clear_inputs(bvr.src_el.getParent(".spt_search"), '.spt_input:not(select.spt_search_filter_mode)'); ''' } ) # {'label': 'Clear', 'tip': 'Clear all search criteria', 'width': 45, # 'bvr': {'cbjs_action': 'spt.api.Utility.clear_inputs(bvr.src_el.getParent(".spt_search"))'} } #] #txt_btn_set = TextBtnSetWdg(buttons=buttons_list, spacing=6, size='small', side_padding=4 ) filter_div.add(search_button) search_button.add_style("float: left") filter_div.add(clear_button) clear_button.add_style("float: left") filter_div.add("<br clear='all'/>") return filter_div
def get_error_wdg(my): div = DivWdg() error_div = DivWdg() error_div.add("Error %s" % my.status) div.add(error_div) error_div.add_style("font-size: 16px") error_div.add_style("font-weight: bold") error_div.add_style("width: 97%") error_div.add_gradient("background", "background") error_div.add_border() error_div.add_style("margin-left: 5px") error_div.add_style("margin-top: -10px") div.add("<br/>") span = DivWdg() #span.add_color("color", "color") span.add_style("color", "#FFF") if my.status == 404: span.add(HtmlElement.b("You have tried to access a url that is not recognized.")) else: span.add(HtmlElement.b(my.message)) span.add(HtmlElement.br(2)) web = WebContainer.get_web() root = web.get_site_root() span.add("Go back to the Main page for a list of valid projects") div.add(span) div.add(HtmlElement.br()) from tactic.ui.widget import ActionButtonWdg button = ActionButtonWdg(title="Go to Main", tip='Click to go to main page') div.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' document.location = '/tactic'; ''' } ) button.add_event("onmouseup", "document.location='/tactic'") button.add_style("margin-left: auto") button.add_style("margin-right: auto") return div
def get_page_four(my): last_page = DivWdg() last_page.add_style("padding-top: 80px") last_page.add_style("padding-left: 30px") cb = CheckboxWdg('jump_to_tab', label='Jump to Tab') cb.set_checked() last_page.add(cb) last_page.add(HtmlElement.br(5)) button_div = DivWdg() create_button = ActionButtonWdg(title="Create >>", tip="Create new project") my.wizard.add_submit_button(create_button) create_button.add_style("float: right") create_button.add_behavior({ 'type': "click_up", 'cbjs_action': ''' spt.alert('perform action here'); ''' }) # you can even pass in a custom cacel_script like # spt.info("You have cancelled") cancel_script = my.kwargs.get("cancel_script") if cancel_script: cancel_button = ActionButtonWdg(title="Cancel") cancel_button.add_style("float: left") cancel_button.add_behavior({ 'type': "click_up", 'cbjs_action': cancel_script }) button_div.add(cancel_button) create_button.add_style("margin-right: 15px") create_button.add_style("margin-left: 75px") button_div.add("<br clear='all'/>") last_page.add(button_div) return last_page
def get_save_button(my,checkin_keys): save_button = ActionButtonWdg(title="Save >>", tip="Save configuration and start using TACTIC") save_button.add_style("float: right") save_button.add_behavior( { 'type': 'click_up', 'os' : os.name, 'checkin_options':checkin_keys, 'cbjs_action': ''' spt.app_busy.show("Saving configuration. Please wait...") var top = bvr.src_el.getParent(".spt_db_config_top"); var values = spt.api.Utility.get_input_values(top, null, false); var class_name = 'tactic.ui.startup.DbConfigSaveCbk'; var server = TacticServerStub.get(); var kwargs = {checkin_options:bvr.checkin_options}; var ret_val = server.execute_cmd(class_name, kwargs, values); var info = ret_val.info; // This means TACTIC was restarted if (typeof(info) == 'undefined' || bvr.os == 'nt' ) { spt.app_busy.show("Restarting TACTIC ..."); var id = setInterval( function() { var ping_rtn = server.ping(); if (ping_rtn) { window.location = '/tactic'; clearInterval(id); } }, 5000 ); } else if (info.error) { spt.alert(info.error); } else { window.location = '/tactic'; } ''' } ) return save_button
def get_display(my): top = DivWdg() top.add_style("width: 100%") top.add_color("background", "background", -10) top.add_style("padding-top: 30px") top.add_style("padding-bottom: 50px") top.add_class("twog_wizard_top") inner = DivWdg() top.add(inner) # set the width and height here inner.add_style("width: 800px") inner.add_style("min-height: 600px") inner.add_style("float: center") inner.add_border() inner.center() inner.add_style("padding: 20px") inner.add_color("background", "background") from tactic.ui.container import WizardWdg title = DivWdg() title.add("Step 1") wizard = WizardWdg(title=title) my.wizard = wizard inner.add(wizard) help_button = ActionButtonWdg(title="?", tip="Step 1 Help", size='s') title.add(help_button) help_button.add_style("float: right") help_button.add_style("margin-top: -20px") help_button.add_style("margin-right: -10px") help_button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.help.set_top(); spt.help.load_alias("order_wdg"); ''' }) page_one = my.get_page_one() wizard.add(page_one, 'Step 1') page_two = my.get_page_two() wizard.add(page_two, 'Step 2') page_three = my.get_page_three() wizard.add(page_three, 'Step 3') page_four = my.get_page_four() wizard.add(page_four, 'Step 4') return top
def get_display(my): alias = my.kwargs.get("alias") div = DivWdg() div.add_style("padding: 15px") div.add_style("margin: 10px") div.add_border() div.add_color("background", "background", -5) div.add_style("text-align: center") div.add_style("font-weight: bold") icon = IconWdg("WARNING", IconWdg.HELP_MISSING) div.add(icon) div.add("Add custom documentation page by clicking the Create button") from tactic.ui.widget import ActionButtonWdg button = ActionButtonWdg(title="Create", tip="Create docs for this view") div.add(button) button.add_style("margin-right: auto") button.add_style("margin-left: auto") button.add_style("margin-top: 15px") button.add_style("margin-bottom: 15px") # FIXME: copied code from above button.add_behavior( { "type": "click_up", "cbjs_action": """ spt.tab.set_main_body_tab(); var class_name = 'tactic.ui.app.HelpEditWdg'; var element_name = spt.help.get_view(); if (!element_name) { element_name = "default"; } var kwargs = { view: element_name } spt.tab.add_new("help_edit", "Help Edit", class_name, kwargs); """, } ) return div
def get_display(my): alias = my.kwargs.get("alias") div = DivWdg() div.add_style("padding: 15px") div.add_style("margin: 10px") div.add_border() div.add_color("background", "background", -5) div.add_style("text-align: center") div.add_style("font-weight: bold") icon = IconWdg("WARNING", IconWdg.HELP_MISSING) div.add(icon) div.add("Add custom documentation page by clicking the Create button") from tactic.ui.widget import ActionButtonWdg button = ActionButtonWdg(title="Create", tip="Create docs for this view") div.add(button) button.add_style("margin-right: auto") button.add_style("margin-left: auto") button.add_style("margin-top: 15px") button.add_style("margin-bottom: 15px") # FIXME: copied code from above button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.tab.set_main_body_tab(); var class_name = 'tactic.ui.app.HelpEditWdg'; var element_name = spt.help.get_view(); if (!element_name) { element_name = "default"; } var kwargs = { view: element_name } spt.tab.add_new("help_edit", "Help Edit", class_name, kwargs); ''' }) return div
def get_display(self): top = self.top self.set_as_panel(top) top.add_class("spt_ingestion_top") top.add_color("background", "background", -5) self.data = {} rules_div = DivWdg() top.add(rules_div) rules_div.add_style("padding: 10px") rules_div.add("Rules: ") rules_select = SelectWdg("rule_code") rule_code = self.get_value('rule_code') if rule_code: rules_select.set_value(rule_code) rules_select.set_option("query", "config/ingest_rule|code|title") rules_select.add_empty_option("-- New --") rules_div.add(rules_select) rules_select.add_behavior( { 'type': 'change', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); value = bvr.src_el.value; var class_name = 'tactic.ui.tools.IngestionToolWdg'; spt.panel.load(top, class_name, {rule_code: value} ); ''' } ) rules_div.add("<hr/>") # read from the database if rule_code: search = Search("config/ingest_rule") search.add_filter("code", rule_code) sobject = search.get_sobject() else: sobject = None if sobject: self.data = sobject.get_value("data") if self.data: self.data = jsonloads(self.data) session_code = self.kwargs.get("session_code") if session_code: session = Search.get_by_code("config/ingest_session", session_code) else: if sobject: session = sobject.get_related_sobject("config/ingest_session") print("sobject: ", sobject.get_code(), sobject.get_value("spt_ingest_session_code")) print("parent: ", session) else: session = None if not session: #session = SearchType.create("config/ingest_session") #session.set_value("code", "session101") #session.set_value("location", "local") ##session.set_value("base_dir", "C:") top.add("No session defined!!!") return top rule = "" filter = "" ignore = "" # get the base path if sobject: base_dir = sobject.get_value("base_dir") else: base_dir = '' #else: # base_dir = self.get_value("base_dir") #if not base_dir: # base_dir = '' if sobject: title = sobject.get_value("title") else: title = '' if sobject: code = sobject.get_value("code") else: code = '' file_list = self.get_value("file_list") scan_type = self.get_value("scan_type") action_type = self.get_value("action_type") rule = self.get_value("rule") if not rule: rule = base_dir # get the rule for this path checkin_mode = "dir" depth = 0 table = Table() rules_div.add(table) table.add_color("color", "color") from tactic.ui.input.text_input_wdg import TextInputWdg # add the title table.add_row() td = table.add_cell() td.add("Title: ") td = table.add_cell() text = TextInputWdg(name="title") td.add(text) if title: text.set_value(title) text.add_class("spt_title") text.add_style("width: 400px") #text.add_color("background", "background", -10) # add the optional code table.add_row() td = table.add_cell() td.add("Code (optional): ") td = table.add_cell() text = TextInputWdg(name="code") td.add(text) if code: text.set_value(code) text.set_readonly() text.add_color("background", "background", -10) text.add_class("spt_code") text.add_style("width: 400px") table.add_row() td = table.add_cell() td.add_style("height: 10px") td.add("<hr/>") table.add_row() td = table.add_cell() td.add("<b>Scan:</b><br/>") td.add("The following information will be used to find the paths that will be operated on by the ingestion process<br/><br/>") # add a scan type table.add_row() td = table.add_cell() td.add("Type: ") select = SelectWdg("scan_type") select.add_class("spt_scan_type") td = table.add_cell() td.add(select) select.set_value( self.get_value("action") ) labels = ['Simple List', 'Rule', 'Script'] values = ['list', 'rule', 'script'] select.set_option("values", values) select.set_option("labels", labels) if scan_type: select.set_value(scan_type) table.add_row() table.add_cell(" ") select.add_behavior( { 'type': 'change', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); value = bvr.src_el.value; var elements = top.getElements(".spt_scan_list"); for (var i = 0; i < elements.length; i++) { if (value == 'list') spt.show(elements[i]); else spt.hide(elements[i]); } var elements = top.getElements(".spt_scan_rule"); for (var i = 0; i < elements.length; i++) { if (value == 'rule') spt.show(elements[i]); else spt.hide(elements[i]); } var elements = top.getElements(".spt_scan_script"); for (var i = 0; i < elements.length; i++) { if (value == 'script') spt.show(elements[i]); else spt.hide(elements[i]); } ''' } ) # add in a list of stuff tbody = table.add_tbody() tbody.add_class("spt_scan_list") if scan_type != 'list': tbody.add_style("display: none") tr = table.add_row() td = table.add_cell() td.add("List of files: ") td = table.add_cell() text = TextAreaWdg(name="file_list") td.add(text) text.add_style("width: 400px") #text.set_readonly() #text.add_color("background", "background", -10) text.set_value(file_list) table.close_tbody() # add rule scan mode tbody = table.add_tbody() tbody.add_class("spt_scan_rule") if scan_type != 'rule': tbody.add_style("display: none") # add the path tr = table.add_row() td = table.add_cell() td.add("Starting Path: ") td = table.add_cell() hidden = HiddenWdg("session_code", session.get_code() ) td.add(hidden) text = TextInputWdg(name="base_dir") td.add(text) text.set_value(base_dir) text.add_style("width: 400px") #text.set_readonly() #text.add_color("background", "background", -10) text.set_value(base_dir) # add rule tr = table.add_row() td = table.add_cell() td.add("Tag Rule: ") td = table.add_cell() text = TextInputWdg(name="rule") td.add(text) text.add_style("width: 400px") text.set_value(rule) tr = table.add_row() td = table.add_cell() td.add("Filter: ") td = table.add_cell() text = TextWdg("filter") td.add(text) text.set_value( self.get_value("filter") ) text.add_style("width: 400px") text.add_style("padding: 2px") text.add_style("-moz-border-radius: 5px") tr = table.add_row() td = table.add_cell() td.add("Ignore: ") td = table.add_cell() text = TextWdg("ignore") td.add(text) text.set_value( self.get_value("ignore") ) text.set_value(ignore) text.add_style("width: 400px") text.add_style("padding: 2px") text.add_style("-moz-border-radius: 5px") table.add_row() td = table.add_cell() td.add("Validation script: ") td.add_style("vertical-align: top") td.add_style("padding-top: 5px") td = table.add_cell() text = TextInputWdg(name="validation_script") text.set_value( self.get_value("validation_script") ) text.add_style("width: 400px") td.add(text) icon = IconButtonWdg(title='Edit Validation Script', icon=IconWdg.EDIT) icon.add_style("float: right") td.add(icon) icon.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.named_events.fire_event("show_script_editor"); var top = bvr.src_el.getParent(".spt_ingestion_top"); var values = spt.api.Utility.get_input_values(top, null, false); var kwargs = { script_path: values.validation_script } setTimeout( function() { spt.js_edit.display_script_cbk(evt, kwargs) }, 500 ); ''' } ) table.close_tbody() # add the script path tbody = table.add_tbody() tbody.add_class("spt_scan_script") if scan_type != 'script': tbody.add_style("display: none") tr = table.add_row() td = table.add_cell() td.add("Script Path: ") td = table.add_cell() text = TextInputWdg(name="script_path") td.add(text) text.add_style("width: 400px") table.close_tbody() table.add_row() td = table.add_cell("<hr/>") table.add_row() td = table.add_cell() td.add("<b>Action</b><br/>") td.add("The following information define the actions that will be used on each matched path<br/><br/>") # pick the type of action table.add_row() td = table.add_cell() td.add("Type: ") select = SelectWdg("action_type") td = table.add_cell() td.add(select) labels = ['Checkin', 'Ignore'] values = ['checkin', 'ignore'] select.set_option("values", values) select.set_option("labels", labels) select.add_empty_option("-- Select --") if action_type: select.set_value(action_type) select.add_behavior( { 'type': 'change', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); value = bvr.src_el.value; var elements = top.getElements(".spt_action_ignore"); for (var i = 0; i < elements.length; i++) { if (value == 'ignore') spt.show(elements[i]); else spt.hide(elements[i]); } var elements = top.getElements(".spt_action_checkin"); for (var i = 0; i < elements.length; i++) { if (value == 'checkin') spt.show(elements[i]); else spt.hide(elements[i]); } ''' } ) table.add_row() td = table.add_cell("<br/>") # add the script path tbody = table.add_tbody() tbody.add_class("spt_action_checkin") if action_type != 'checkin': tbody.add_style("display: none") # add the checkin type table.add_row() td = table.add_cell() td.add("Action: ") select = SelectWdg("action") td = table.add_cell() td.add(select) select.set_value( self.get_value("action") ) labels = ['File Checkin', 'Directory Checkin', 'Sequence Checkin'] values = ['file', 'directory', 'sequence', 'ignore'] select.set_option("values", values) select.set_option("labels", labels) table.add_row() td = table.add_cell() td.add("Mode: ") select = SelectWdg("mode") td = table.add_cell() td.add(select) labels = ['Copy', 'Move', 'In Place'] values = ['copy', 'move', 'inplace'] select.set_option("values", values) select.set_option("labels", labels) # add the search_type table.add_row() td = table.add_cell() td.add("sType: ") td = table.add_cell() select = SelectWdg("search_type") td.add(select) search_types = Project.get().get_search_types() values = [x.get_value("search_type") for x in search_types] select.set_option("values", values) search_type = self.kwargs.get("search_type") if search_type: select.set_value(search_type) # add the search_type table.add_row() td = table.add_cell() td.add("Context: ") td = table.add_cell() select = SelectWdg("context") td.add(select) select.set_option("values", ['publish', 'by rule', 'custom']) # add extra values extra_div = DivWdg() text = TextWdg("extra_name") text.add_attr("spt_is_multiple", "true") extra_div.add(text) extra_div.add(" = ") text = TextWdg("extra_value") extra_div.add(text) text.add_attr("spt_is_multiple", "true") template_div = DivWdg() text = TextWdg("extra_name") text.add_attr("spt_is_multiple", "true") template_div.add(text) template_div.add(" = ") text = TextWdg("extra_value") template_div.add(text) text.add_attr("spt_is_multiple", "true") table.close_tbody() table.add_row() td = table.add_cell("<br/>") table.add_row() td = table.add_cell() td.add("Extra Keywords: ") td.add_style("vertical-align: top") td.add_style("padding-top: 5px") td = table.add_cell() text = TextWdg("keywords") text.add_style("width: 300px") td.add(text) table.add_row() td = table.add_cell() td.add("Extra Values: ") td.add_style("vertical-align: top") td.add_style("padding-top: 5px") td = table.add_cell() extra_list = DynamicListWdg() td.add(extra_list) extra_list.add_item(extra_div) extra_list.add_template(template_div) table.add_row() table.add_cell(" ") table.add_row() td = table.add_cell() td.add("Process script: ") td.add_style("vertical-align: top") td.add_style("padding-top: 5px") td = table.add_cell() text = TextWdg("process_script") text.add_style("width: 300px") td.add(text) text.set_value( self.get_value("process_script") ) icon = IconButtonWdg(title='Edit Process Script', icon=IconWdg.EDIT) icon.add_style("float: right") td.add(icon) icon.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.named_events.fire_event("show_script_editor"); var top = bvr.src_el.getParent(".spt_ingestion_top"); var values = spt.api.Utility.get_input_values(top, null, false); var kwargs = { script_path: values.process_script } // need to wait for this setTimeout( function() { spt.js_edit.display_script_cbk(evt, kwargs) }, 500 ); ''' } ) table.add_row() td = table.add_cell() td.add("Custom Naming: ") td.add_style("vertical-align: top") td.add_style("padding-top: 5px") td = table.add_cell() text = TextWdg("naming") text.add_style("width: 300px") td.add(text) table.add_row() td = table.add_cell() #td.add("<br clear='all'/>") td.add("<hr/>") behavior = { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); var values = spt.api.Utility.get_input_values(top, null, false); spt.app_busy.show("Scanning ...", values.base_dir); var class_name = 'tactic.ui.tools.IngestionProcessWdg'; var server = TacticServerStub.get(); values.mode = bvr.mode; values.is_local = 'true'; // scan client side if (values.is_local == 'true') { var base_dir = values.base_dir; var applet = spt.Applet.get(); var files = applet.list_recursive_dir(base_dir); // turn into a string var files_in_js = []; for (var i = 0; i < files.length; i++) { var file = files[i].replace(/\\\\/g, "/"); files_in_js.push( file ); } values.files = files_in_js; values.base_dir = base_dir; /* var server = TacticServerStub.get(); var handoff_dir = server.get_handoff_dir(); var applet = spt.Applet.get(); for (var i = 0; i < files_in_js.length; i++) { try { var parts = files_in_js[i].split("/"); var filename = parts[parts.length-1]; spt.app_busy.show("Copying files to handoff", filename); applet.copy_file(files_in_js[i], handoff_dir+"/"+filename); } catch(e) { log.error(e); } } */ } var info_el = top.getElement(".spt_info"); spt.panel.load(info_el, class_name, values); spt.app_busy.hide(); ''' } # Save button button = ActionButtonWdg(title="Save", tip="Save Rule") td.add(button) button.add_style("float: right") behavior['mode'] = 'save' button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); var values = spt.api.Utility.get_input_values(top, null, false); spt.app_busy.show("Saving ..."); var class_name = 'tactic.command.CheckinRuleSaveCmd'; var server = TacticServerStub.get(); server.execute_cmd(class_name, values); spt.panel.refresh(top, {}); spt.app_busy.hide(); ''' } ) # Scan button button = ActionButtonWdg(title="Scan", tip="Click to Scan") td.add(button) button.add_style("float: left") # set a limit #limit = TextWdg("limit") #td.add(limit) #text.add_style("float: left") behavior = behavior.copy() behavior['mode'] = 'scan' button.add_behavior(behavior) # Test button button = ActionButtonWdg(title="Test", tip="Do a test of this rule") td.add(button) behavior = behavior.copy() behavior['mode'] = 'test' button.add_behavior(behavior) button.add_style("float: left") # Ingest button button = ActionButtonWdg(title="Ingest", tip="Click to start ingesting") td.add(button) behavior = behavior.copy() behavior['mode'] = 'checkin' button.add_behavior(behavior) table.add_behavior( { 'type': 'listen', 'event_name': 'file_browser|select', 'cbjs_action': ''' var dirname = bvr.firing_data.dirname; var top = bvr.src_el.getParent(".spt_ingestion_top"); var kwargs = { base_dir: dirname }; spt.panel.load(top, top.getAttribute("spt_class_name"), kwargs); ''' }) top.add( self.get_info_wdg() ) return top
def get_display(self): session_code = self.kwargs.get("session_code") session_code = 'session101' session = Search.get_by_code("config/ingest_session", session_code) data = session.get_json_value("data") if data == None: data = {} top = self.top top.add_class("spt_ingest_dir_list_top") self.set_as_panel(top) inner = DivWdg() top.add(inner) inner.add_style("padding: 10px") inner.add_color("background", "background") base_dir = self.kwargs.get("base_dir") location = self.kwargs.get("location") rescan = self.kwargs.get("rescan") if rescan in [True, 'true']: rescan = True else: rescan = False rescan = ActionButtonWdg(title='Rescan', tip="Rescan file system") inner.add(rescan) rescan.add_style("float: right") rescan.add_behavior( { 'type': 'click_up', 'base_dir': base_dir, 'cbjs_action': ''' spt.app_busy.show("Scanning", "Scanning files in " + bvr.base_dir); var top = bvr.src_el.getParent(".spt_ingest_dir_list_top"); spt.panel.refresh(top); spt.app_busy.hide(); ''' } ) import datetime last_scan = datetime.datetime.now() last_scan_wdg = DivWdg() inner.add(last_scan_wdg) last_scan_wdg.add("Last Scan: %s" % last_scan) last_scan_wdg.add_style("margin-bottom: 5px") found_wdg = DivWdg() inner.add(found_wdg) found_wdg.add_style("margin-bottom: 5px") inner.add("<hr/>") show_handled = self.kwargs.get("show_handled") show_handled = False if show_handled in [False, 'false']: try: scan_path = "/tmp/scan" import codecs f = codecs.open(scan_path, 'r', 'utf-8') ignore = jsonloads( f.read() ) f.close() except Exception as e: print("Error: ", e.message) ignore = None else: ignore = None # check for rescan cache_key = self.kwargs.get("cache_key") rescan = True if rescan == True: paths = [] else: paths = data.get(cache_key) if not paths: paths = [] dir_list_wdg = DirListWdg(paths=paths, base_dir=base_dir, location=location, ignore=ignore, depth=2) # cache the paths if rescan: paths = dir_list_wdg.get_paths() data['paths'] = paths session.set_json_value("data", data) session.commit() # add the paths found num_paths = dir_list_wdg.get_num_paths() found_wdg.add("Found: %s items" % num_paths) inner.add(dir_list_wdg) return top
def get_nav_wdg(self): #base_dir = self.kwargs.get("base_dir") #location = self.kwargs.get("location") base_dir = self.session.get_value("base_dir") location = self.session.get_value("location") nav_wdg = DivWdg() nav_wdg.add("<b>Session 101 - Clean up self Crap</b><hr/>") nav_wdg.add_style("margin-bottom: 10px") nav_wdg.add_class("spt_file_nav") nav_wdg.add_style("width: 575px") nav_wdg.add_border() nav_wdg.set_round_corners() nav_wdg.add_style("padding: 5px") button = ActionButtonWdg(title="Scan", tip="Scan for files in specified folder") button.add_style("float: right") button.add_style("margin-top: -5px") nav_wdg.add(button) from tactic.ui.input import TextInputWdg title_wdg = "Session Title: " nav_wdg.add(title_wdg) text = TextInputWdg(name="title") text.add_class("spt_title") text.add_style("width: 300px") nav_wdg.add(text) nav_wdg.add("<br/><br/>") folder_wdg = "Base folder of this session: " nav_wdg.add(folder_wdg) text = TextInputWdg(name="base_dir") text.add_class("spt_base_dir") text.add_style("width: 300px") if base_dir: text.set_value(base_dir) nav_wdg.add(text) # add a hidden paths variable text = HiddenWdg("paths") text.add_class("spt_paths") nav_wdg.add(text) nav_wdg.add("<br/>") # add a hidden paths variable select = SelectWdg("location") if location: select.set_value(location) nav_wdg.add("<br/>") nav_wdg.add("Folder is on ") nav_wdg.add(select) select.set_option("values", "local|server") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); var nav = top.getElement(".spt_file_nav"); var nav_values = spt.api.Utility.get_input_values(nav,null,false); var base_dir = nav_values.base_dir; var location = nav_values.location; spt.app_busy.show("Scanning", base_dir); if (location == 'local') { var applet = spt.Applet.get(); var paths = applet.list_dir(base_dir, 2); var paths_el = nav.getElement(".spt_paths"); var js_paths = []; for (var i = 0; i < paths.length; i++) { var js_path = paths[i].replace(/\\\\/g,"/"); if (applet.is_dir(js_path) ) { js_path = js_path + '/'; js_paths.push(js_path); } //if (i > 100) break; else { js_paths.push(js_path); } } paths_el.value = js_paths.join("|"); } //var nav_values = spt.api.Utility.get_input_values(nav,null,false); //spt.panel.refresh(top, nav_values); spt.tab.set_tab_top(top); spt.tab.select("files") var class_name = "tactic.ui.tools.IngestionToolDirListWdg"; var kwargs = { base_dir: base_dir, location: location, paths: js_paths } spt.tab.load_selected("files", "Files", class_name, kwargs); spt.app_busy.hide(); ''' } ) return nav_wdg
def get_display(my): relative_dir = my.kwargs.get("relative_dir") my.relative_dir = relative_dir div = DivWdg() div.add_class("spt_ingest_top") div.add_style("width: 100%px") div.add_style("min-width: 500px") div.add_style("padding: 20px") div.add_color("background", "background") my.search_type = my.kwargs.get("search_type") if not my.search_type: div.add("No search type specfied") return div if relative_dir: folder_div = DivWdg() div.add(folder_div) folder_div.add("Folder: %s" % relative_dir) folder_div.add_style("opacity: 0.5") folder_div.add_style("font-style: italic") folder_div.add_style("margin-bottom: 10px") data_div = my.get_data_wdg() data_div.add_style("float: left") data_div.add_style("float: left") div.add(data_div) # create the help button help_button_wdg = DivWdg() div.add(help_button_wdg) help_button_wdg.add_style("float: right") help_button = ActionButtonWdg(title="?", tip="Ingestion Widget Help", size='s') help_button_wdg.add(help_button) help_button.add_behavior({ 'type': 'click_up', 'cbjs_action': '''spt.help.load_alias("ingestion_widget")''' }) from tactic.ui.input import Html5UploadWdg upload = Html5UploadWdg(multiple=True) div.add(upload) button = ActionButtonWdg(title="Add") button.add_style("float: right") button.add_style("margin-top: -3px") div.add(button) button.add_behavior({ 'type': 'click_up', 'normal_ext': File.NORMAL_EXT, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingest_top"); var files_el = top.getElement(".spt_to_ingest_files"); var regex = new RegExp('(' + bvr.normal_ext.join('|') + ')$', 'i'); //clear upload progress var upload_bar = top.getElement('.spt_upload_progress'); if (upload_bar) { upload_bar.setStyle('width','0%'); upload_bar.innerHTML = ''; } var onchange = function (evt) { var files = spt.html5upload.get_files(); var delay = 0; for (var i = 0; i < files.length; i++) { var size = files[i].size; var file_name = files[i].name; var is_normal = regex.test(file_name); if (size >= 10*1024*1024 || is_normal) { spt.drag.show_file(files[i], files_el, 0, false); } else { spt.drag.show_file(files[i], files_el, delay, true); if (size < 100*1024) delay += 50; else if (size < 1024*1024) delay += 500; else if (size < 10*1024*1024) delay += 1000; } } } spt.html5upload.clear(); spt.html5upload.set_form( top ); spt.html5upload.select_file( onchange ); ''' }) button = ActionButtonWdg(title="Clear") button.add_style("float: right") button.add_style("margin-top: -3px") div.add(button) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingest_top"); var file_els = top.getElements(".spt_upload_file"); for ( var i = 0; i < file_els.length; i++) { spt.behavior.destroy( file_els[i] ); }; ''' }) div.add("<br clear='all'/>") div.add("<br clear='all'/>") border_color_light = div.get_color("background2", 8) border_color_dark = div.get_color("background2", -15) background_mouseout = div.get_color("background3", 10) background_mouseenter = div.get_color("background3", 8) files_div = DivWdg() files_div.add_style("position: relative") files_div.add_class("spt_to_ingest_files") div.add(files_div) files_div.add_style("max-height: 300px") files_div.add_style("height: 300px") files_div.add_style("overflow-y: auto") files_div.add_style("padding: 3px") files_div.add_color("background", background_mouseout) files_div.add_style("border: 3px dashed %s" % border_color_light) files_div.add_style("border-radius: 20px 20px 20px 20px") files_div.add_style("z-index: 1") #files_div.add_style("display: none") bgcolor = div.get_color("background3") bgcolor2 = div.get_color("background3", -3) #style_text = "text-align: center; margin-top: 100px; color: #A0A0A0; font-size: 3.0em; z-index: 10;" background = DivWdg() background.add_class("spt_files_background") files_div.add(background) background.add_style("text-align: center") background.add_style("margin-top: 100px") background.add_style("opacity: 0.65") background.add_style("font-size: 3.0em") background.add_style("z-index: 10") background_text = DivWdg("<p>Drag Files Here</p>") background.add(background_text) files_div.add_behavior({ 'type': 'mouseover', 'cbjs_action': ''' bvr.src_el.setStyle("border","3px dashed %s") bvr.src_el.setStyle("background","%s") ''' % (border_color_dark, background_mouseenter) }) files_div.add_behavior({ 'type': 'mouseout', 'cbjs_action': ''' bvr.src_el.setStyle("border", "3px dashed %s") bvr.src_el.setStyle("background","%s") ''' % (border_color_light, background_mouseout) }) # Test drag and drop files files_div.add_attr("ondragenter", "return false") files_div.add_attr("ondragover", "return false") files_div.add_attr("ondrop", "spt.drag.noop(event, this)") files_div.add_behavior({ 'type': 'load', 'normal_ext': File.NORMAL_EXT, 'cbjs_action': ''' spt.drag = {} var background; spt.drag.show_file = function(file, top, delay, icon) { if (!background) { background = top.getElement(".spt_files_background"); if (background) background.setStyle("display", "none"); } var template = top.getElement(".spt_upload_file_template"); var clone = spt.behavior.clone(template); clone.removeClass("spt_upload_file_template"); clone.addClass("spt_upload_file"); clone.setStyle("display", ""); if (typeof(delay) == 'undefined') { delay = 0; } // remember the file handle clone.file = file; var name = file.name; var size = parseInt(file.size / 1024 * 10) / 10; var thumb_el = clone.getElement(".spt_thumb"); var date_label_el = clone.getElement(".spt_date_label"); var date_el = clone.getElement(".spt_date"); //var loadingImage = loadImage( setTimeout( function() { var draw_empty_icon = function() { var img = $(document.createElement("div")); img.setStyle("width", "58"); img.setStyle("height", "34"); //img.innerHTML = "MP4"; img.setStyle("border", "1px dotted #222") thumb_el.appendChild(img); }; if (icon) { var loadingImage = loadImage( file, function (img) { if (img.width) thumb_el.appendChild(img); else draw_empty_icon(); }, {maxWidth: 80, maxHeight: 60, canvas: true, contain: true} ); } else { draw_empty_icon(); } loadImage.parseMetaData( file, function(data) { if (data.exif) { var date = data.exif.get('DateTimeOriginal'); if (date) { date_label_el.innerHTML = date; if (date_el) { date_el.value = date; } } } } ); }, delay ); /* var reader = new FileReader(); reader.thumb_el = thumb_el; reader.onload = function(e) { this.thumb_el.innerHTML = [ '<img class="thumb" src="', e.target.result, '" title="', escape(name), '" width="60px"', '" padding="5px"', '"/>' ].join(''); } reader.readAsDataURL(file); */ clone.getElement(".spt_name").innerHTML = file.name; clone.getElement(".spt_size").innerHTML = size + " KB"; clone.inject(top); } spt.drag.noop = function(evt, el) { var top = $(el).getParent(".spt_ingest_top"); var files_el = top.getElement(".spt_to_ingest_files"); evt.stopPropagation(); evt.preventDefault(); evt.dataTransfer.dropEffect = 'copy'; var files = evt.dataTransfer.files; var delay = 0; var skip = false; var regex = new RegExp('(' + bvr.normal_ext.join('|') + ')$', 'i'); for (var i = 0; i < files.length; i++) { var size = files[i].size; var file_name = files[i].name; var is_normal = regex.test(file_name); if (size >= 10*1024*1024 || is_normal) { spt.drag.show_file(files[i], files_el, 0, false); } else { spt.drag.show_file(files[i], files_el, delay, true); if (size < 100*1024) delay += 50; else if (size < 1024*1024) delay += 500; else if (size < 10*1024*1024) delay += 1000; } } } ''' }) # create a template that will be filled in for each file files_div.add_relay_behavior({ 'type': 'mouseenter', 'color': files_div.get_color("background3", -5), 'bvr_match_class': 'spt_upload_file', 'cbjs_action': ''' bvr.src_el.setStyle("background", bvr.color); ''' }) files_div.add_relay_behavior({ 'type': 'mouseleave', 'bvr_match_class': 'spt_upload_file', 'cbjs_action': ''' bvr.src_el.setStyle("background", ""); ''' }) files_div.add_relay_behavior({ 'type': 'mouseup', 'bvr_match_class': 'spt_remove', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_upload_file"); spt.behavior.destroy_element(top); ''' }) """ metadata_view = "test/wizard/metadata" files_div.add_relay_behavior( { 'type': 'mouseup', 'view': metadata_view, 'bvr_match_class': 'spt_upload_file', 'cbjs_action': ''' var class_name = 'tactic.ui.panel.CustomLayoutWdg'; var kwargs = { view: bvr.view } spt.app_busy.show("Loading Metadata"); spt.panel.load_popup("Metadata", class_name, kwargs); spt.app_busy.hide(); ''' } ) """ # template for each file item file_template = DivWdg() file_template.add_class("spt_upload_file_template") files_div.add(file_template) file_template.add_style("margin-bottom: 3px") file_template.add_style("padding: 3px") file_template.add_style("height: 40px") file_template.add_style("display: none") thumb_div = DivWdg() file_template.add(thumb_div) thumb_div.add_style("float: left") thumb_div.add_style("width: 60") thumb_div.add_style("height: 40") thumb_div.add_style("overflow: hidden") thumb_div.add_style("margin: 3 10 3 0") thumb_div.add_class("spt_thumb") info_div = DivWdg() file_template.add(info_div) info_div.add_style("float: left") name_div = DivWdg() name_div.add_class("spt_name") info_div.add(name_div) name_div.add("image001.jpg") name_div.add_style("width: 150px") """ dialog = DialogWdg(display="false", show_title=False) info_div.add(dialog) dialog.set_as_activator(info_div, offset={'x':0,'y':10}) dialog_data_div = DivWdg() dialog_data_div.add_color("background", "background") dialog_data_div.add_style("padding", "10px") dialog.add(dialog_data_div) dialog_data_div.add("Category: ") text = TextInputWdg(name="category") dialog_data_div.add(text) text.add_class("spt_category") text.add_style("padding: 1px") """ date_div = DivWdg() date_div.add_class("spt_date_label") info_div.add(date_div) date_div.add("") date_div.add_style("opacity: 0.5") date_div.add_style("font-size: 0.8em") date_div.add_style("font-style: italic") date_div.add_style("margin-top: 3px") hidden_date_div = HiddenWdg("date") hidden_date_div.add_class("spt_date") info_div.add(date_div) size_div = DivWdg() size_div.add_class("spt_size") file_template.add(size_div) size_div.add("433Mb") size_div.add_style("float: left") size_div.add_style("width: 150px") size_div.add_style("text-align: right") remove_div = DivWdg() remove_div.add_class("spt_remove") file_template.add(remove_div) icon = IconButtonWdg(title="Remove", icon=IconWdg.DELETE) icon.add_style("float: right") remove_div.add(icon) #remove_div.add_style("text-align: right") div.add("<br/>") info = DivWdg() div.add(info) info.add_class("spt_upload_info") progress_div = DivWdg() progress_div.add_class("spt_upload_progress_top") div.add(progress_div) progress_div.add_style("width: 100%") progress_div.add_style("height: 15px") progress_div.add_style("margin-bottom: 10px") progress_div.add_border() #progress_div.add_style("display: none") progress = DivWdg() progress_div.add(progress) progress.add_class("spt_upload_progress") progress.add_style("width: 0px") progress.add_style("height: 100%") progress.add_gradient("background", "background3", -10) progress.add_style("text-align: right") progress.add_style("overflow: hidden") progress.add_style("padding-right: 3px") from tactic.ui.app import MessageWdg progress.add_behavior({ 'type': 'load', 'cbjs_action': MessageWdg.get_onload_js() }) # NOTE: files variable is passed in automatically upload_init = ''' server.start( {description: "Upload and check-in of ["+files.length+"] files"} ); var info_el = top.getElement(".spt_upload_info"); info_el.innerHTML = "Uploading ..."; ''' upload_progress = ''' var top = bvr.src_el.getParent(".spt_ingest_top"); progress_el = top.getElement(".spt_upload_progress"); var percent = Math.round(evt.loaded * 100 / evt.total); progress_el.setStyle("width", percent + "%"); progress_el.innerHTML = String(percent) + "%"; ''' oncomplete_script_path = my.kwargs.get("oncomplete_script_path") oncomplete_script = '' if oncomplete_script_path: script_folder, script_title = oncomplete_script_path.split("/") oncomplete_script_expr = "@GET(config/custom_script['folder','%s']['title','%s'].script)" % ( script_folder, script_title) server = TacticServerStub.get() oncomplete_script_ret = server.eval(oncomplete_script_expr, single=True) if oncomplete_script_ret: oncomplete_script = '''var top = bvr.src_el.getParent(".spt_ingest_top"); var file_els = top.getElements(".spt_upload_file"); for ( var i = 0; i < file_els.length; i++) { spt.behavior.destroy( file_els[i] ); };''' + oncomplete_script_ret script_found = True else: script_found = False oncomplete_script = "alert('Error: oncomplete script not found');" if not oncomplete_script: oncomplete_script = ''' var click_action = function() { var fade = true; var pop = spt.popup.get_popup(top) spt.popup.close(pop, fade); } spt.info("Ingest Completed", {click: click_action}); server.finish(); var file_els = top.getElements(".spt_upload_file"); for ( var i = 0; i < file_els.length; i++) { spt.behavior.destroy( file_els[i] ); }; var background = top.getElement(".spt_files_background"); background.setStyle("display", ""); spt.message.stop_interval(key); var info_el = top.getElement(".spt_upload_info"); info_el.innerHTML = ''; if (spt.table) { spt.table.run_search(); } spt.panel.refresh(top); ''' script_found = True on_complete = ''' var top = bvr.src_el.getParent(".spt_ingest_top"); var update_data_top = top.getElement(".spt_edit_top"); var progress_el = top.getElement(".spt_upload_progress"); progress_el.innerHTML = "100%"; progress_el.setStyle("width", "100%"); var info_el = top.getElement(".spt_upload_info"); var search_type = bvr.kwargs.search_type; var relative_dir = bvr.kwargs.relative_dir; var update_mode_select = top.getElement(".spt_update_mode_select"); var update_mode = update_mode_select.value; var filenames = []; for (var i = 0; i != files.length;i++) { var name = files[i].name; filenames.push(name); } var key = spt.message.generate_key(); var values = spt.api.get_input_values(top); //var category = values.category[0]; //var keywords = values.keywords[0]; var extra_data = values.extra_data ? values.extra_data[0]: {}; var parent_key = values.parent_key[0]; var convert_el = top.getElement(".spt_image_convert") var convert = spt.api.get_input_values(convert_el); var processes = values.process; if (processes) { process = processes[0]; if (!process) { process = null; } } else { process = null; } var return_array = false; var update_data = spt.api.get_input_values(update_data_top, null, return_array); var kwargs = { search_type: search_type, relative_dir: relative_dir, filenames: filenames, key: key, parent_key: parent_key, //category: category, //keywords: keywords, extra_data: extra_data, update_data: update_data, process: process, convert: convert, update_mode: update_mode, } on_complete = function(rtn_data) { ''' + oncomplete_script + ''' }; var class_name = bvr.action_handler; // TODO: make the async_callback return throw an e so we can run // server.abort server.execute_cmd(class_name, kwargs, null, {on_complete:on_complete}); on_progress = function(message) { msg = JSON.parse(message.message); var percent = msg.progress; var description = msg.description; info_el.innerHTML = description; progress_el.setStyle("width", percent+"%"); progress_el.innerHTML = percent + "%"; } spt.message.set_interval(key, on_progress, 2000); ''' upload_div = DivWdg() div.add(upload_div) #button = UploadButtonWdg(**kwargs) button = ActionButtonWdg(title="Ingest") upload_div.add(button) button.add_style("float: right") upload_div.add_style("margin-bottom: 15px") upload_div.add("<br clear='all'/>") action_handler = my.kwargs.get("action_handler") if not action_handler: action_handler = 'tactic.ui.tools.IngestUploadCmd' button.add_behavior({ 'type': 'click_up', 'action_handler': action_handler, 'kwargs': { 'search_type': my.search_type, 'relative_dir': relative_dir, 'script_found': script_found, }, 'cbjs_action': ''' if (bvr.kwargs.script_found != true) { spt.alert("Error: provided on_complete script not found"); return; } var top = bvr.src_el.getParent(".spt_ingest_top"); var file_els = top.getElements(".spt_upload_file"); // get the server that will be used in the callbacks var server = TacticServerStub.get(); // retrieved the stored file handles var files = []; for (var i = 0; i < file_els.length; i++) { files.push( file_els[i].file ); } if (files.length == 0) { alert("Either click 'Add' or drag some files over to ingest."); return; } // defined the callbacks var upload_start = function(evt) { } var upload_progress = function(evt) { %s; } var upload_complete = function(evt) { %s; spt.app_busy.hide(); } var upload_file_kwargs = { files: files, upload_start: upload_start, upload_complete: upload_complete, upload_progress: upload_progress }; if (bvr.ticket) upload_file_kwargs['ticket'] = bvr.ticket; %s; spt.html5upload.set_form( top ); spt.html5upload.upload_file(upload_file_kwargs); ''' % (upload_progress, on_complete, upload_init) }) return div
def get_display(my): top = my.top view = my.kwargs.get("view") top.add_class("spt_help_edit_content") search = Search("config/widget_config") search.add_filter("category", "HelpWdg") search.add_filter("view", view) sobject = search.get_sobject() if not sobject: value = "" search_key = "" else: xml_value = sobject.get_xml_value("config") value = xml_value.get_value("config/%s/html/div" % (view) ) search_key = sobject.get_search_key() title_wdg = DivWdg() top.add(title_wdg) title_wdg.add("<b>View: %s</b>" % view) title_wdg.add_style("font-style: bold") title_wdg.add_style("padding: 5px") title_wdg.add_gradient("background", "background", 0, -10) hidden = HiddenWdg("view") top.add(hidden) hidden.set_value(view) text = TextAreaWdg("content") text_id = text.set_unique_id() text.set_value(value) from tactic.ui.widget import ActionButtonWdg if sobject: delete_button = ActionButtonWdg(title="Delete") top.add(delete_button) delete_button.add_style("float: right") delete_button.add_style("margin-top: -3px") delete_button.add_behavior( { 'type': 'click_up', 'search_key': search_key, 'cbjs_action': ''' if (!confirm("Are you sure you wish to delete this help page?")) { return; } var server = TacticServerStub.get(); server.delete_sobject(bvr.search_key); var top = bvr.src_el.getParent(".spt_help_edit_top"); spt.panel.refresh(top); ''' }) test_button = ActionButtonWdg(title="Preview") top.add(test_button) test_button.add_style("float: right") test_button.add_style("margin-top: -3px") test_button.add_behavior( { 'type': 'click_up', 'text_id': text_id, 'cbjs_action': ''' var js_file = "ckeditor/ckeditor.js"; var url = "/context/spt_js/" + js_file; var js_el = document.createElement("script"); js_el.setAttribute("type", "text/javascript"); js_el.setAttribute("src", url); var head = document.getElementsByTagName("head")[0]; head.appendChild(js_el); var cmd = "CKEDITOR.instances." + bvr.text_id + ".getData()"; var text_value = eval( cmd ); bvr.options = {}; bvr.options.html = text_value; spt.named_events.fire_event("show_help", bvr) ''' }) save_button = ActionButtonWdg(title="Save") top.add(save_button) save_button.add_style("float: right") save_button.add_style("margin-top: -3px") top.add("<br/>") save_button.add_behavior( { 'type': 'click_up', 'text_id': text_id, 'cbjs_action': ''' spt.app_busy.show("Saving Help", " ") var top = bvr.src_el.getParent(".spt_help_edit_content"); var values = spt.api.Utility.get_input_values(top, null, false); var cmd = "CKEDITOR.instances." + bvr.text_id + ".getData()"; var text_value = eval( cmd ); values.content = text_value; var command = "tactic.ui.app.HelpEditCbk"; var kwargs = values; var server = TacticServerStub.get(); server.execute_cmd(command, kwargs); setTimeout("spt.app_busy.hide()", 200) ''' } ) #top.add("Style: ") #select = SelectWdg("style") #top.add(select) #select.set_option("values", "text|html") top.add("<br/>") top.add(text) text.set_value(value) text.add_style("width: 100%") text.add_style("height: 100%") text.add_style("min-height: 500px") text.add_style("display: none") text.add_behavior( { 'type': 'load', 'color': text.get_color("background", -10), 'text_id': text_id, 'cbjs_action': ''' var js_file = "ckeditor/ckeditor.js"; var url = "/context/spt_js/" + js_file; var js_el = document.createElement("script"); js_el.setAttribute("type", "text/javascript"); js_el.setAttribute("src", url); var head = document.getElementsByTagName("head")[0]; head.appendChild(js_el); setTimeout( function() { CKEDITOR.on( 'instanceReady', function( ev ) { ev.editor.dataProcessor.writer.indentationChars = ' '; }); var config = { toolbar: 'Full', uiColor: bvr.color, height: '500px' }; config.toolbar_Full = [ ['Source'], ['Cut','Copy','Paste'], ['Undo','Redo','-','Find','Replace'], ['Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'], ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'], '/', ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'], ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'], ['HorizontalRule','SpecialChar'], ['Styles','Format','Font','FontSize'], ['TextColor','BGColor'], ['Maximize', 'ShowBlocks'] ]; CKEDITOR.replace(bvr.text_id, config ); bvr.src_el.setStyle("display", ""); }, 500); ''' } ) return top
def get_display(my): data = my.kwargs.get('kwargs') if data: data = jsonloads(data) my.kwargs.update(data) my.search_type = my.kwargs.get("search_type") my.x_axis = my.kwargs.get("x_axis") if not my.x_axis: my.x_axis = 'code' my.y_axis = my.kwargs.get("y_axis") if type(my.y_axis) == types.ListType: my.y_axis = "|".join(my.y_axis) my.chart_type = my.kwargs.get("chart_type") if not my.chart_type: my.chart_type = 'bar' # get any search keys if any are passed in my.search_keys = my.kwargs.get("search_keys") top = DivWdg() top.add_class("spt_chart_builder") top.add_color("background", "background") top.add_border() from tactic.ui.app import HelpButtonWdg help_button = HelpButtonWdg(alias='charting') top.add(help_button) help_button.add_style("float: right") project = Project.get() search_types = project.get_search_types(include_sthpw=True) search_types = [x.get_value("search_type") for x in search_types] build_div = DivWdg() from pyasm.widget import SwapDisplayWdg swap_wdg = SwapDisplayWdg.get_triangle_wdg() swap_script = swap_wdg.get_swap_script() build_div.add(swap_wdg) build_div.add("<b>Chart Specifications</b>") build_div.add_style("margin-bottom: 5px") build_div.add_style("height: 25px") build_div.add_style("padding-top: 5px") build_div.add_gradient("background", "background", -10) build_div.add_color("color", "color") build_div.add_class("hand") build_div.add_class("SPT_DTS") top.add(build_div) build_div.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_chart_builder"); var spec = top.getElement(".spt_chart_spec"); //spt.api.toggle_show_hide(spec); spt.toggle_show_hide(spec); %s; ''' % swap_script }) spec_div = DivWdg() spec_div.add_color("color", "color3") spec_div.add_color("background", "background3") spec_div.add_class("spt_chart_spec") spec_div.add_border() spec_div.add_style("padding: 10px") spec_div.add_style("margin: 5px") spec_div.add_style("display: none") top.add(spec_div) table = Table() table.add_color("color", "color3") spec_div.add(table) # add the search type selector table.add_row() table.add_cell("Search Type: ") search_type_div = DivWdg() search_type_select = TextWdg("search_type") search_type_select.set_value(my.search_type) #search_type_select.set_option("values", search_types) search_type_div.add(search_type_select) table.add_cell(search_type_div) # add the chart type selector table.add_row() table.add_cell("Chart Type: ") type_div = DivWdg() #type_div.add_style("padding: 3px") type_select = SelectWdg("chart_type") type_select.set_option("values", "line|bar|area") if my.chart_type: type_select.set_value(my.chart_type) type_div.add(type_select) table.add_cell(type_div) # add the chart type selector table.add_row() table.add_cell("X-Axis: ") # need to find all expression widgets or use get_text_value()? x_axis_div = DivWdg() x_axis_text = TextWdg("x_axis") x_axis_text.set_value("code") x_axis_div.add(x_axis_text) table.add_cell(x_axis_div) # add the chart type selector table.add_row() td = table.add_cell("Y-Axis: ") td.add_style("vertical-align: top") y_axis_div = DivWdg() #y_axis_text = TextWdg("y_axis") #if my.y_axis: # y_axis_text.set_value(my.y_axis) #y_axis_div.add(y_axis_text) td = table.add_cell(y_axis_div) # add in a list of entries from tactic.ui.container import DynamicListWdg list_wdg = DynamicListWdg() for value in my.y_axis.split("|"): item = TextWdg("y_axis") item.set_value(value, set_form_value=False) list_wdg.add_item(item) y_axis_div.add(list_wdg) spec_div.add("<br/>") from tactic.ui.widget import ActionButtonWdg button = ActionButtonWdg(title="Refresh") spec_div.add(button) spec_div.add(HtmlElement.br(2)) button.add_style("float: left") button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_chart_builder"); var chart = top.getElement(".spt_chart"); var values = spt.api.get_input_values(top); //var values = spt.api.Utility.get_input_values(top); spt.panel.refresh(chart, values); ''' }) #TODO: provide a field for user to type in the chart name """ button = ActionButtonWdg(title="Save") spec_div.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_chart_builder"); var chart = top.getElement(".spt_chart"); var values = spt.api.get_input_values(top); var login = '******'; var search_type = 'SideBarWdg'; var side_bar_view = 'project_view'; var unique_el_name = 'chart_test' var kwargs = {}; kwargs['login'] = null; //if (save_as_personal) // kwargs['login'] = login; kwargs['class_name'] = 'tactic.ui.chart.ChartBuilderWdg'; var display_options = {}; display_options['search_type'] = 'prod/asset' kwargs['display_options'] = display_options; kwargs['unique'] = true; //if (new_title) // kwargs['element_attrs'] = {'title': new_title}; var server = TacticServerStub.get() server.add_config_element(search_type, side_bar_view, unique_el_name, kwargs); spt.panel.refresh("side_bar"); ''' } ) """ width = '600px' kwargs = { 'y_axis': my.y_axis, 'chart_type': my.chart_type, 'search_type': my.search_type, 'width': width, 'search_keys': my.search_keys } chart_div = DivWdg() chart = BarChartWdg(**kwargs) chart_div.add(chart) top.add(chart_div) #from chart2_wdg import SampleSObjectChartWdg #chart = SampleSObjectChartWdg(**kwargs) #chart_div.add(chart) return top
def get_nav_wdg(self): #base_dir = self.kwargs.get("base_dir") #location = self.kwargs.get("location") base_dir = self.session.get_value("base_dir") location = self.session.get_value("location") nav_wdg = DivWdg() nav_wdg.add("<b>Session 101 - Clean up self Crap</b><hr/>") nav_wdg.add_style("margin-bottom: 10px") nav_wdg.add_class("spt_file_nav") nav_wdg.add_style("width: 575px") nav_wdg.add_border() nav_wdg.set_round_corners() nav_wdg.add_style("padding: 5px") button = ActionButtonWdg(title="Scan", tip="Scan for files in specified folder") button.add_style("float: right") button.add_style("margin-top: -5px") nav_wdg.add(button) from tactic.ui.input import TextInputWdg title_wdg = "Session Title: " nav_wdg.add(title_wdg) text = TextInputWdg(name="title") text.add_class("spt_title") text.add_style("width: 300px") nav_wdg.add(text) nav_wdg.add("<br/><br/>") folder_wdg = "Base folder of this session: " nav_wdg.add(folder_wdg) text = TextInputWdg(name="base_dir") text.add_class("spt_base_dir") text.add_style("width: 300px") if base_dir: text.set_value(base_dir) nav_wdg.add(text) # add a hidden paths variable text = HiddenWdg("paths") text.add_class("spt_paths") nav_wdg.add(text) nav_wdg.add("<br/>") # add a hidden paths variable select = SelectWdg("location") if location: select.set_value(location) nav_wdg.add("<br/>") nav_wdg.add("Folder is on ") nav_wdg.add(select) select.set_option("values", "local|server") button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); var nav = top.getElement(".spt_file_nav"); var nav_values = spt.api.Utility.get_input_values(nav,null,false); var base_dir = nav_values.base_dir; var location = nav_values.location; spt.app_busy.show("Scanning", base_dir); if (location == 'local') { var applet = spt.Applet.get(); var paths = applet.list_dir(base_dir, 2); var paths_el = nav.getElement(".spt_paths"); var js_paths = []; for (var i = 0; i < paths.length; i++) { var js_path = paths[i].replace(/\\\\/g,"/"); if (applet.is_dir(js_path) ) { js_path = js_path + '/'; js_paths.push(js_path); } //if (i > 100) break; else { js_paths.push(js_path); } } paths_el.value = js_paths.join("|"); } //var nav_values = spt.api.Utility.get_input_values(nav,null,false); //spt.panel.refresh(top, nav_values); spt.tab.set_tab_top(top); spt.tab.select("files") var class_name = "tactic.ui.tools.IngestionToolDirListWdg"; var kwargs = { base_dir: base_dir, location: location, paths: js_paths } spt.tab.load_selected("files", "Files", class_name, kwargs); spt.app_busy.hide(); ''' }) return nav_wdg
def get_display(my): web = WebContainer.get_web() login_name = web.get_form_value('login') hidden = HiddenWdg('login', login_name) box = DivWdg(css='login') if web.is_IE(): box.add_style("margin-top: 150px") box.add_style("margin-bottom: 150px") else: box.add_style("margin-top: auto") box.add_style("margin-bottom: auto") box.add_style("text-align: center") div = DivWdg() div.add_style("margin: 0px 0px") div.add_class("centered") div.add_style("padding-top: 95px") sthpw = SpanWdg("SOUTHPAW TECHNOLOGY INC", css="login_sthpw") sthpw.add_style("color: #CCCCCC") div.add(sthpw) div.add(HtmlElement.br()) div.add(hidden) box.add(div) # hidden element in the form to pass message that this was not # actually a typical submitted form, but rather the result # of a login page div.add(HiddenWdg("is_from_login", "yes")) div.add_style("font-size: 10px") table = Table(css="login") table.center() table.set_attr("cellpadding", "3px") table.add_row() table2 = Table(css="login") table2.center() table2.add_style("width: 240px") table2.add_row() td = table2.add_header( 'After reset, the new password will be sent to the email address for [ %s ].' % login_name) td.add_color('color', 'color', +80) table2.add_row_cell(' ') # build the button manually from tactic.ui.widget import ActionButtonWdg button = ActionButtonWdg(tip='Reset Password', title='Reset') button.add_style('margin: auto') button.add_event( 'onclick', "document.form.elements['reset_password'].value='true'; document.form.submit()" ) table2.add_row() td = table2.add_cell(button) hidden = HiddenWdg('reset_password') td.add(hidden) #th.add_class('center_content') table2.add_row() div.add(HtmlElement.br()) div.add(table) div.add(HtmlElement.spacer_div(1, 14)) div.add(table2) #div.add(HiddenWdg(my.LOGIN_MSG)) #box.add(script) widget = Widget() #widget.add( HtmlElement.br(3) ) table = Table() table.add_style("width: 100%") table.add_style("height: 85%") table.add_row() td = table.add_cell() td.add_style("vertical-align: middle") td.add_style("text-align: center") td.add_style("background: transparent") td.add(box) widget.add(table) return widget
def get_buttons_wdg(my): button_div = DivWdg() button = ActionButtonWdg(title='Run') button_div.add(button) button.add_style("float: left") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_script_editor_top"); var code = top.getElement(".spt_code").value; var folder = top.getElement(".spt_folder").value; var title = top.getElement(".spt_title").value; var language = top.getElement(".spt_language").value; spt.ace_editor.set_editor_top(top); var editor = spt.ace_editor.editor; var value = editor.getSession().toString(); try { if (language == 'javascript') { eval(value); } else if (language == 'expression') { var server = TacticServerStub.get(); var ret_val; ret_val = server.eval(value); if (ret_val && ret_val.length) { for (var i = 0; i < ret_val.length; i++) { log.critical(ret_val[i]); } } else { log.critical(ret_val); } } else if (language == 'python') { var path = folder + "/" + title; var server = TacticServerStub.get(); var info = server.execute_python_script(path); log.critical(info); } else if (language == 'server_js') { var path = folder + "/" + title; var server = TacticServerStub.get(); var info = server.execute_js_script(path); log.critical(info); } else { var ok = function() { eval(value);} spt.confirm("Please set the language of this script. It's assumed to be javascript if left blank. Continue to run?", ok, null); } } catch(e) { spt.error(spt.exception.handler(e)); } ''' } ) button = ActionButtonWdg(title='Save') button_div.add(button) button.add_style("float: left") button.add_behavior( { 'type': 'click_up', 'editor_id': my.unique_id, 'cbjs_action': ''' /* if (!has_changes(bvr)) { spt.alert("No changes have been made"); return; } */ var top = bvr.src_el.getParent(".spt_script_editor_top"); spt.app_busy.show("Saving Script ..."); setTimeout(function() { spt.ace_editor.set_editor_top(top); spt.script_editor.save_script_cbk(evt, bvr); spt.app_busy.hide(); }, 10); ''' } ) button = ActionButtonWdg(title='Clear') button_div.add(button) button.add_style("float: left") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.api.Utility.clear_inputs( bvr.src_el.getParent('.spt_js_editor') ); var top = bvr.src_el.getParent(".spt_script_editor_top"); spt.ace_editor.set_editor_top(top); var editor = spt.ace_editor.editor; var document = editor.getSession().getDocument() document.setValue(""); ''' } ) button = ActionButtonWdg(title='Resize') #button_div.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var editor = spt.ace_editor.editor; var editor_id = spt.ace_editor.editor_id; $(editor_id).setStyle("width", "1000px"); $(editor_id).setStyle("height", "800px"); editor.resize(); ''' } ) return button_div
def get_display(my): div = DivWdg() div.add_class("spt_security") div.add_attr("id", "SecurityManagerWdg") div.add_attr("spt_class_name", Common.get_full_class_name(my) ) div.add_attr("spt_search_key", my.search_key) div.add_attr("spt_update", "true") project_div = DivWdg() project_div.add_color("background", "background") project_div.add_color("color", "color") project_div.add_style("padding: 10px") project_div.add_border() project_div.add_style("width: 300px") group = SearchKey.get_by_search_key(my.search_key) title = DivWdg() title.add_class("maq_search_bar") name = group.get_value("login_group") title.add("Global security settings for %s" % name) project_div.add(title) access_rules = group.get_xml_value("access_rules") access_manager = AccessManager() access_manager.add_xml_rules(access_rules) group = "builtin" global_default_access = "deny" list_div = DivWdg() list_div.add_style("color: #222") for item in permission_list: if item.get('group'): group_div = DivWdg() list_div.add(group_div) group_div.add_style("margin-top: 10px") group_div.add_style("font-weight: bold") group_div.add(item.get('group')) group_div.add("<hr/>") continue item_div = DivWdg() list_div.add(item_div) item_div.add_style("margin-top: 5px") key = item.get('key') item_default = item.get('default') if item_default: default_access = item_default else: default_access = global_default_access allowed = access_manager.check_access(group, key, "allow", default=default_access) checkbox = CheckboxWdg("rule") if allowed: checkbox.set_checked() checkbox.set_option("value", key) item_div.add(checkbox) item_div.add_style("color: #222") item_div.add(item.get('title') ) project_div.add(list_div) project_div.add("<hr>") #close_script = "spt.popup.close(bvr.src_el.getParent('.spt_popup'))" save_button = ActionButtonWdg(title="Save", tip="Save Security Settings") save_button.add_behavior( { "type": "click_up", "cbjs_action": "el=bvr.src_el.getParent('.spt_security');spt.panel.refresh(el);" } ) save_button.add_style("margin-left: auto") save_button.add_style("margin-right: auto") project_div.add(save_button) div.add(project_div) if my.update == "true": div.add(HtmlElement.br()) div.add(HtmlElement.b(my.description)) return div
def get_display(self): top = self.top top.add_color("background", "background") top.add_class("spt_pipelines_top") self.set_as_panel(top) inner = DivWdg() top.add(inner) search_type = self.kwargs.get("search_type") pipeline_code = self.kwargs.get("pipeline_code") if search_type: search = Search("sthpw/pipeline") search.add_filter("search_type", search_type) pipelines = search.get_sobjects() else: pipeline = Pipeline.get_by_code(pipeline_code) if pipeline: pipelines = [pipeline] else: pipelines = [] if not pipelines: div = DivWdg() inner.add(div) inner.add_style("padding: 50px") div.add_border() div.add_color("color", "color3") div.add_color("background", "background3") div.add_style("width: 400px") div.add_style("height: 100px") div.add_style("padding: 30px") icon = IconWdg("WARNING", IconWdg.WARNING) div.add(icon) div.add("<b>This Searchable Type does not have pipelines defined.</b>") div.add("<br/>"*2) div.add("<b style='padding-left: 35px'>Click Create to add one...</b>") div.add("<br/>"*2) button_div = DivWdg() div.add(button_div) button = ActionButtonWdg(title="Create", tip="Create pipeline") button_div.add(button) button.add_style("margin: auto") button.add_behavior( { 'type': 'click_up', 'search_type': search_type, 'cbjs_action': ''' var server = TacticServerStub.get(); var cmd = 'tactic.ui.startup.PipelineCreateCbk'; var kwargs = { search_type: bvr.search_type } server.execute_cmd(cmd, kwargs) var top = bvr.src_el.getParent(".spt_pipelines_top"); spt.panel.refresh(top); ''' } ) return top # get the defalt task statuses task_pipeline = Pipeline.get_by_code("task") if task_pipeline: statuses = task_pipeline.get_process_names() else: statuses = ['Pending', 'In Progress', 'Complete'] statuses_str = ",".join(statuses) pipelines_div = DivWdg() inner.add( pipelines_div ) pipelines_div.add_style("font-size: 12px") pipelines_div.add_style("padding: 10px") buttons_div = DivWdg() pipelines_div.add(buttons_div) #button = SingleButtonWdg( title="Save Pipelines", icon=IconWdg.SAVE ) button = ActionButtonWdg( title="Save" ) buttons_div.add(button) button.add_behavior( { 'type': 'click_up', 'default_statuses': statuses_str, 'cbjs_action': ''' spt.app_busy.show("Saving Pipeline...") setTimeout(function() { try { var top = bvr.src_el.getParent(".spt_pipelines_top"); // get all the pipeline divs var pipeline_els = top.getElements(".spt_pipeline_top"); var data = {}; for ( var i = 0; i < pipeline_els.length; i++) { var pipeline_code = pipeline_els[i].getAttribute("spt_pipeline_code"); var values = spt.api.Utility.get_input_values(pipeline_els[i]); data[pipeline_code] = values; } var class_name = 'tactic.ui.startup.PipelineEditCbk'; var kwargs = { data: data } var server = TacticServerStub.get(); server.execute_cmd(class_name, kwargs); } catch(e) { spt.alert(spt.exception.handler(e)); } spt.app_busy.hide(); } , 100); ''' } ) buttons_div.add("<br clear='all'/>") buttons_div.add_style("margin-bottom: 5px") for pipeline in pipelines: pipeline_div = DivWdg() pipelines_div.add(pipeline_div) pipeline_div.add_class("spt_pipeline_top") code = pipeline.get_code() label = '%s (%s)' %(pipeline.get('name'), code) pipeline_div.add_attr("spt_pipeline_code", code) title = DivWdg() pipeline_div.add(title) title.add("Pipeline: ") title.add(label) title.add_style("padding: 8px 10px") title.add_color("background", "background3") title.add_style("font-weight: bold") title.add_style("margin: -10 -10 5 -10") header_wdg = DivWdg() pipeline_div.add(header_wdg) header_wdg.add_color("background", "background", -5) headers = ['Process', 'Description', 'Task Status'] widths = ['100px', '180px', '210px'] for header, width in zip(headers,widths): th = DivWdg() header_wdg.add(th) th.add("<b>%s</b>" % header) th.add_style("float: left") th.add_style("width: %s" % width) th.add_style("padding: 8px 3px") header_wdg.add("<br clear='all'/>") # get all of the process sobjects from this pipeline pipeline_code = pipeline.get_code() search = Search("config/process") search.add_filter("pipeline_code", pipeline.get_code() ) process_sobjs = search.get_sobjects() process_sobj_dict = {} for process_sobj in process_sobjs: process = process_sobj.get_value("process") process_sobj_dict[process] = process_sobj from tactic.ui.container import DynamicListWdg dyn_list = DynamicListWdg() pipeline_div.add(dyn_list) pipeline_div.add_style("width: 725px") processes = pipeline.get_process_names() if not processes: processes.append("") processes.append("") processes.append("") processes.insert(0, "") for i, process in enumerate(processes): if process == '': process_name = '' description = '' else: process_sobj = process_sobj_dict.get(process) if process_sobj: process_name = process_sobj.get_value("process") description = process_sobj.get_value("description") else: if isinstance(process,basestring): process_name = process else: process_name = process.get_name() deccription = '' process_type = 'manual' process_xpos = '' process_ypos = '' # get the task pipeline for this process if process_name: process = pipeline.get_process(process_name) process_type = process.get_type() process_xpos = process.get_attribute('xpos') process_ypos = process.get_attribute('ypos') task_pipeline_code = process.get_task_pipeline() if task_pipeline_code != "task": task_pipeline = Search.get_by_code("sthpw/pipeline", task_pipeline_code) else: task_pipeline = None else: task_pipeline_code = "task" task_pipeline = None process_div = DivWdg() process_div.add_style("float: left") process_div.add_class("spt_process_top") if i == 0: dyn_list.add_template(process_div) else: dyn_list.add_item(process_div) #process_div.add_style("padding-left: 10px") #process_div.add_style("margin: 5px") table = Table() process_div.add(table) table.add_row() text = TextInputWdg(name="process") process_cell = table.add_cell(text) text.add_style("width: 95px") text.add_style("margin: 5px") text.set_value(process_name) text.add_class("spt_process") # the template has a border if i == 0: text.add_style("border: solid 1px #AAA") hidden = HiddenWdg(name='process_type') hidden.set_value(process_type) process_cell.add(hidden) hidden = HiddenWdg(name='process_xpos') hidden.set_value(process_xpos) process_cell.add(hidden) hidden = HiddenWdg(name='process_ypos') hidden.set_value(process_ypos) process_cell.add(hidden) text = TextInputWdg(name="description") table.add_cell(text) text.add_style("width: 175px") text.add_style("margin: 5px") text.set_value(description) # the template has a border if i == 0: text.add_style("border: solid 1px #AAA") if process_type in ['manual','approval']: read_only = False else: read_only = True text = TextInputWdg(name="task_status", read_only=read_only) table.add_cell(text) text.add_style("width: 325px") text.add_style("margin: 5px") #text.set_value(statuses_str) #text.add_style("opacity: 0.5") text.add_style("border-style: none") if process_type in ['manual','approval']: if task_pipeline: statuses = task_pipeline.get_process_names() text.set_value(",".join(statuses)) else: text.set_value("(default)") text.add_behavior( { 'type': 'click_up', 'statuses': statuses_str, 'cbjs_action': ''' if (bvr.src_el.value == '(default)') { bvr.src_el.value = bvr.statuses; } ''' } ) table.add_cell(" "*2) button = IconButtonWdg(tip="Trigger", icon=IconWdg.ARROW_OUT) table.add_cell(button) button.add_behavior( { 'type': 'click_up', 'search_type': search_type, 'pipeline_code': pipeline_code, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_process_top"); var process_el = top.getElement(".spt_process"); var process = process_el.value; if (process == "") { alert("Process value is empty"); return; } var class_name = 'tactic.ui.tools.TriggerToolWdg'; var kwargs = { mode: "pipeline", process: process, pipeline_code: bvr.pipeline_code }; spt.panel.load_popup("Trigger", class_name, kwargs); ''' } ) """ button = IconButtonWdg(tip="Edit", icon=IconWdg.EDIT) table.add_cell(button) button.add_behavior( { 'type': 'click_up', 'search_type': search_type, 'pipeline_code': pipeline_code, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_process_top"); var process_el = top.getElement(".spt_process"); var process = process_el.value; if (process == "") { alert("Process value is empty"); return; } var class_name = 'tactic.ui.panel.EditWdg'; var kwargs = { expression: "@SOBJECT(config/process['process','"+process+"'])" } spt.panel.load_popup("Trigger", class_name, kwargs); ''' } ) """ table.add_cell(" "*3) pipeline_div.add("<br clear='all'/>") pipeline_div.add("<br clear='all'/>") if self.kwargs.get("is_refresh"): return inner else: return top
def get_data_wdg(my): div = DivWdg() from pyasm.biz import Pipeline from pyasm.widget import SelectWdg search_type_obj = SearchType.get(my.search_type) base_type = search_type_obj.get_base_key() search = Search("sthpw/pipeline") search.add_filter("search_type", base_type) pipelines = search.get_sobjects() if pipelines: pipeline = pipelines[0] process_names = pipeline.get_process_names() if process_names: table = Table() div.add(table) table.add_row() table.add_cell("Process: ") select = SelectWdg("process") table.add_cell(select) process_names.append("---") process_names.append("publish") process_names.append("icon") select.set_option("values", process_names) #### buttons = Table() div.add(buttons) buttons.add_row() #button = IconButtonWdg(title="Fill in Data", icon=IconWdg.EDIT) button = ActionButtonWdg(title="Metadata") button.add_style("float: left") button.add_style("margin-top: -3px") buttons.add_cell(button) select_label = DivWdg("Update mode") select_label.add_style("float: left") select_label.add_style("margin-top: -3px") select_label.add_style("margin-left: 20px") buttons.add_cell(select_label) update_mode_option = my.kwargs.get("update_mode") if not update_mode_option: update_mode_option = "true" update_mode = SelectWdg(name="update mode") update_mode.add_class("spt_update_mode_select") update_mode.set_option("values", ["false", "true", "sequence"]) update_mode.set_option("labels", ["Off", "On", "Sequence"]) update_mode.set_option("default", update_mode_option) update_mode.add_style("float: left") update_mode.add_style("margin-top: -3px") update_mode.add_style("margin-left: 5px") update_mode.add_style("margin-right: 5px") buttons.add_cell(update_mode) update_info = DivWdg() update_info.add_class("glyphicon") update_info.add_class("glyphicon-info-sign") update_info.add_style("float: left") update_info.add_style("margin-top: -3px") update_info.add_style("margin-left: 10px") update_info.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.info("When update mode is on, if a file shares the name of one other file in the asset library, the file will update on ingest. If more than one file shares the name of an ingested asset, a new asset is created.<br> If sequence mode is selected, the system will update the sobject on ingest if a file sequence sharing the same name already exists.", {type: 'html'}); ''' }) buttons.add_cell(update_info) dialog = DialogWdg(display="false", show_title=False) div.add(dialog) dialog.set_as_activator(button, offset={'x': -10, 'y': 10}) dialog_data_div = DivWdg() dialog_data_div.add_color("background", "background") dialog_data_div.add_style("padding", "20px") dialog.add(dialog_data_div) # Order folders by date name_div = DivWdg() dialog_data_div.add(name_div) name_div.add_style("margin: 15px 0px") if SearchType.column_exists(my.search_type, "relative_dir"): category_div = DivWdg() name_div.add(category_div) checkbox = RadioWdg("category") checkbox.set_option("value", "none") category_div.add(checkbox) category_div.add(" No categories") category_div.add_style("margin-bottom: 5px") checkbox.set_option("checked", "true") category_div = DivWdg() name_div.add(category_div) checkbox = RadioWdg("category") checkbox.set_option("value", "by_day") category_div.add(checkbox) category_div.add(" Categorize files by Day") category_div.add_style("margin-bottom: 5px") category_div = DivWdg() name_div.add(category_div) checkbox = RadioWdg("category") checkbox.set_option("value", "by_week") category_div.add(checkbox) category_div.add(" Categorize files by Week") category_div.add_style("margin-bottom: 5px") category_div = DivWdg() name_div.add(category_div) checkbox = RadioWdg("category") checkbox.set_option("value", "by_year") category_div.add(checkbox) category_div.add(" Categorize files by Year") category_div.add_style("margin-bottom: 5px") """ checkbox = RadioWdg("category") checkbox.set_option("value", "custom") name_div.add(checkbox) name_div.add(" Custom") """ name_div.add("<br/>") ingest_data_view = my.kwargs.get('ingest_data_view') from tactic.ui.panel import EditWdg sobject = SearchType.create(my.search_type) edit = EditWdg(search_key=sobject.get_search_key(), mode='view', view=ingest_data_view) dialog_data_div.add(edit) hidden = HiddenWdg(name="parent_key") dialog_data_div.add(hidden) hidden.add_class("spt_parent_key") parent_key = my.kwargs.get("parent_key") or "" if parent_key: hidden.set_value(parent_key) extra_data = my.kwargs.get("extra_data") if not isinstance(extra_data, basestring): extra_data = jsondumps(extra_data) if extra_data and extra_data != "null": # it needs a TextArea instead of Hidden because of JSON data text = TextAreaWdg(name="extra_data") text.add_style('display: none') text.set_value(extra_data) dialog_data_div.add(text) """ dialog_data_div.add("Keywords:<br/>") dialog.add(dialog_data_div) text = TextAreaWdg(name="keywords") dialog_data_div.add(text) text.add_class("spt_keywords") text.add_style("padding: 1px") dialog_data_div.add("<br/>"*2) text.add_class("spt_extra_data") text.add_style("padding: 1px") """ #### TEST Image options """ button = IconButtonWdg(title="Resize", icon=IconWdg.FILM) buttons.add_cell(button) dialog = DialogWdg(display="false", show_title=False) div.add(dialog) dialog.set_as_activator(button, offset={'x':-10,'y':10}) try: from spt.tools.convert import ConvertOptionsWdg convert_div = DivWdg() dialog.add(convert_div) convert_div.add_style("padding: 20px") convert_div.add_color("background", "background") convert_div.add_class("spt_image_convert") convert = ConvertOptionsWdg() convert_div.add(convert) except: pass """ # use base name for name """ name_div = DivWdg() dialog_data_div.add(name_div) name_div.add_style("margin: 15px 0px") checkbox = CheckboxWdg("use_file_name") name_div.add(checkbox) name_div.add(" Use name of file for name") name_div.add("<br/>") checkbox = CheckboxWdg("use_base_name") name_div.add(checkbox) name_div.add(" Remove extension") name_div.add("<br/>") checkbox = CheckboxWdg("file_keywords") name_div.add(checkbox) name_div.add(" Use file name for keywords") """ return div
def get_display(my): top = my.top my.set_as_panel(top) top.add_class("spt_delete_top") top.add_color("background", "background") top.add_color("color", "color") top.add_border() top.add_style("width: 300px") top.add_border() search_key = my.kwargs.get("search_key") search_keys = my.kwargs.get("search_keys") if search_key: sobject = Search.get_by_search_key(search_key) sobjects = [sobject] search_keys = [search_key] elif search_keys: sobjects = Search.get_by_search_keys(search_keys) sobject = sobjects[0] if not sobjects: msg = "%s not found" %search_key return msg search_type = sobject.get_base_search_type() if search_type in ['sthpw/project', 'sthpw/search_object']: msg = 'You cannot delete these items with this tool' return msg my.search_keys = search_keys title = DivWdg() top.add(title) title.add_color("background", "background", -10) if my.search_keys: title.add("Delete %s Items" % len(my.search_keys)) else: title.add("Delete Item [%s]" % (sobject.get_code())) title.add_style("font-size: 14px") title.add_style("font-weight: bold") title.add_style("padding: 10px") content = DivWdg() top.add(content) content.add_style("padding: 10px") content.add("The item to be deleted has a number of dependencies as described below:<br/>", 'heading') # find all the relationships schema = Schema.get() related_types = schema.get_related_search_types(search_type, direction="children") parent_type = schema.get_parent_type(search_type) child_types = schema.get_child_types(search_type) # some special considerations # FIXME: this needs to be more automatic. Should only be # deletable children (however, that will be defined) if search_type in ['sthpw/task','sthpw/note', 'sthpw/snapshot']: if "sthpw/project" in related_types: related_types.remove("sthpw/project") if "sthpw/login" in related_types: related_types.remove("sthpw/login") if "config/process" in related_types: related_types.remove("config/process") if parent_type in related_types: related_types.remove(parent_type) related_types.append('sthpw/note') related_types.append('sthpw/task') related_types.append('sthpw/snapshot') if 'sthpw/work_hour' not in related_types: related_types.append('sthpw/work_hour') items_div = DivWdg() content.add( items_div ) items_div.add_style("padding: 10px") valid_related_ctr = 0 for related_type in related_types: if related_type == "*": print "WARNING: related_type is *" continue if related_type == search_type: continue if related_type in ['sthpw/search_object','sthpw/search_type']: continue item_div = my.get_item_div(sobjects, related_type) if item_div: items_div.add(item_div) valid_related_ctr += 1 if valid_related_ctr > 0: icon = IconWdg("WARNING", IconWdg.WARNING) icon.add_style("float: left") content.add( icon ) content.add("<div><b>WARNING: By selecting the related items above, you can delete them as well when deleting this sObject.</b></div>") content.add("<br/>"*2) else: # changed the heading to say no dependencies content.add("The item to be deleted has no dependencies.<br/>", 'heading') content.add("There are %s items to be deleted" % len(my.search_keys)) content.add("<br/>"*2) content.add("Do you wish to continue deleting?") content.add("<br/>"*2) button_div = DivWdg() button_div.add_styles('width: 300px; height: 50px') button = ActionButtonWdg(title="Delete") button_div.add(button) content.add(button_div) button.add_style("float: left") button.add_behavior( { 'type': 'click_up', 'search_keys': my.search_keys, 'cbjs_action': ''' spt.app_busy.show("Deleting"); var top = bvr.src_el.getParent(".spt_delete_top"); var values = spt.api.Utility.get_input_values(top); var class_name = "tactic.ui.tools.DeleteCmd"; var kwargs = { 'search_keys': bvr.search_keys, 'values': values }; var server = TacticServerStub.get(); try { server.start({'title': 'Delete sObject', 'description': 'Delete sObject [' + bvr.search_keys + ']'}); server.execute_cmd(class_name, kwargs); server.finish(); // run the post delete and destroy the popup var popup = bvr.src_el.getParent(".spt_popup"); if (popup.spt_on_post_delete) { popup.spt_on_post_delete(); } spt.popup.destroy(popup); } catch(e) { spt.alert(spt.exception.handler(e)); } spt.app_busy.hide(); ''' } ) button = ActionButtonWdg(title="Cancel") button.add_style("float: left") button_div.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_popup"); top.destroy(); ''' } ) content.add("<br clear='all'/>") return top
def get_session_wdg(self): div = DivWdg() div.add_style("width: 150px") search = Search("config/ingest_rule") rules = search.get_sobjects() add = ActionButtonWdg(title="+", tip="Add new rule", size='small') div.add(add) add.add_style("margin-top: -6px") add.add_behavior({ 'type': 'click_up', 'session_code': self.session.get_code(), 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); spt.tab.set_tab_top(top); var class_name = 'tactic.ui.tools.IngestionToolWdg'; var kwargs = { session_code: bvr.session_code }; spt.tab.select("rules"); spt.tab.load_selected("rules", "Rules", class_name, kwargs); ''' }) add.add_style("float: right") div.add("<b>Rules</b><hr/>") if not rules: div.add("<br/><i>No rules found</i><br/>") for rule in rules: rule_code = rule.get_code() rule_title = rule.get_value("title") rule_div = DivWdg() div.add(rule_div) rule_div.add_style("padding: 3px") hover = rule_div.get_color("background", -10) rule_div.add_behavior({ 'type': 'hover', 'hover': hover, 'cbjs_action_over': ''' bvr.src_el.setStyle("background", bvr.hover); ''', 'cbjs_action_out': ''' bvr.src_el.setStyle("background", ""); ''' }) rule_div.add_class("hand") checkbox = CheckboxWdg("whatever") rule_div.add(checkbox) rule_div.add(rule_title) rule_div.add_behavior({ 'type': 'click_up', 'rule_code': rule_code, 'session_code': self.session_code, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); spt.tab.set_tab_top(top); var class_name = 'tactic.ui.tools.IngestionToolWdg'; var kwargs = { location: 'server', rule_code: bvr.rule_code, session_code: bvr.session_code }; spt.tab.select("rules"); spt.tab.load_selected("rules", "Rules", class_name, kwargs); ''' }) return div
def get_display(my): top = my.top top.add_style("height: 100%") top.add_style("overflow-x: hidden") top.set_unique_id() width = my.kwargs.get("width") if width: top.add_style("width: %s" % width) from tactic.ui.panel import CustomLayoutWdg html = my.kwargs.get("html") view = my.kwargs.get("view") alias = my.kwargs.get("alias") if alias: aliases = alias.split("|") alias = aliases[0] aliases = aliases[1:] else: aliases = [] top.add_relay_behavior( { 'type': 'mouseover', 'bvr_match_class': 'spt_link', 'cbjs_action': ''' spt.mouse.table_layout_hover_over({}, {src_el: bvr.src_el, add_color_modifier: -5}); ''' } ) top.add_relay_behavior( { 'type': 'mouseout', 'bvr_match_class': 'spt_link', 'cbjs_action': ''' spt.mouse.table_layout_hover_out({}, {src_el: bvr.src_el}) ''' } ) top.add_smart_style("spt_link", "margin-left", "5px") if alias == 'main': top.add_smart_style("spt_link", "text-decoration", "none") else: top.add_smart_style("spt_link", "text-decoration", "underline") top.add_smart_style("spt_link", "padding", "1px") if aliases: related_wdg = my.get_related_wdg(aliases) top.add( related_wdg ) rel_path = my.kwargs.get("rel_path") # attempt to get if from the widget config search = Search("config/widget_config") search.add_filter("category", "HelpWdg") search.add_filter("view", alias) config = search.get_sobject() if html: layout = CustomLayoutWdg(html=html, view=view) top.add(layout) # config can override alias elif config: layout = CustomLayoutWdg(config=config, view=alias) author = config.get_value("login") timestamp = config.get_value("timestamp") top.add(layout) elif alias: widget = HelpDocFilterWdg(alias=alias) top.add(widget) elif rel_path: widget = HelpDocFilterWdg(rel_path=rel_path) top.add(widget) elif not view: layout = DivWdg() top.add(layout) allow_create = my.kwargs.get("allow_create") if allow_create not in ['false', False]: layout.add(HelpCreateWdg()) else: layout.add("No documentation found") layout.add_style("padding: 30px 20px") layout.add_style("margin-left: auto") layout.add_style("margin-right: auto") layout.add_style("margin-top: 50px") layout.add_style("text-align: center") layout.add_style("width: 250px;") layout.add_color("background", "background3") layout.add_color("color", "color3") layout.add_border() elif view == 'default': top.add(my.get_default_wdg()) else: author = "TACTIC" timestamp = None search = Search("config/widget_config") search.add_filter("category", "HelpWdg") search.add_filter("view", view) config = search.get_sobject() if config: layout = CustomLayoutWdg(config=config, view=view) author = config.get_value("login") timestamp = config.get_value("timestamp") else: # get it from the file system layout = DivWdg() install_dir = Environment.get_install_dir() path = "%s/src/context/help/%s.html" % (install_dir,view) if os.path.exists(path): f = open(path) html = f.read() f.close() layout.add(html) else: div = DivWdg() layout.add(div) div.add_style("padding: 15px") div.add_style("margin: 10px") div.add_border() div.add_color("background", "background", -5) div.add_style("text-align: center") div.add_style("font-weight: bold") icon = IconWdg("WARNING", IconWdg.WARNING) div.add(icon) div.add("There are no help pages available for this key [%s]<br/><br/>" % view) div.add("<br/>") div.add("Click to create a new custom doc:") from tactic.ui.widget import ActionButtonWdg button = ActionButtonWdg(title="Create", tip="Create docs for this view") div.add(button) button.add_style("margin-right: auto") button.add_style("margin-left: auto") button.add_style("margin-top: 15px") button.add_style("margin-bottom: 15px") # FIXME: copied code from above button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.tab.set_main_body_tab(); var class_name = 'tactic.ui.app.HelpEditWdg'; var element_name = spt.help.get_view(); if (!element_name) { element_name = "default"; } var kwargs = { view: element_name } spt.tab.add_new("help_edit", "Help Edit", class_name, kwargs); ''' } ) layout.add_style("margin-top: 10px") info_div = DivWdg() info_div.add("<i>Author: %s</i>" % author) info_div.add_style("opacity: 0.5") info_div.add_style("font-size: 10px") info_div.add_style("position: absolute") info_div.add_style("bottom: 20px") content_div = DivWdg() top.add(content_div) content_div.add_style("padding: 5px") content_div.add(layout) top.add(info_div) #top.add(HelpContentWdg.get_default_wdg(aliases)) return top
def get_display(self): session_code = self.kwargs.get("session_code") session_code = 'session101' session = Search.get_by_code("config/ingest_session", session_code) data = session.get_json_value("data") if data == None: data = {} top = self.top top.add_class("spt_ingest_dir_list_top") self.set_as_panel(top) inner = DivWdg() top.add(inner) inner.add_style("padding: 10px") inner.add_color("background", "background") base_dir = self.kwargs.get("base_dir") location = self.kwargs.get("location") rescan = self.kwargs.get("rescan") if rescan in [True, 'true']: rescan = True else: rescan = False rescan = ActionButtonWdg(title='Rescan', tip="Rescan file system") inner.add(rescan) rescan.add_style("float: right") rescan.add_behavior({ 'type': 'click_up', 'base_dir': base_dir, 'cbjs_action': ''' spt.app_busy.show("Scanning", "Scanning files in " + bvr.base_dir); var top = bvr.src_el.getParent(".spt_ingest_dir_list_top"); spt.panel.refresh(top); spt.app_busy.hide(); ''' }) import datetime last_scan = datetime.datetime.now() last_scan_wdg = DivWdg() inner.add(last_scan_wdg) last_scan_wdg.add("Last Scan: %s" % last_scan) last_scan_wdg.add_style("margin-bottom: 5px") found_wdg = DivWdg() inner.add(found_wdg) found_wdg.add_style("margin-bottom: 5px") inner.add("<hr/>") show_handled = self.kwargs.get("show_handled") show_handled = False if show_handled in [False, 'false']: try: scan_path = "/tmp/scan" import codecs f = codecs.open(scan_path, 'r', 'utf-8') ignore = jsonloads(f.read()) f.close() except Exception as e: print("Error: ", e.message) ignore = None else: ignore = None # check for rescan cache_key = self.kwargs.get("cache_key") rescan = True if rescan == True: paths = [] else: paths = data.get(cache_key) if not paths: paths = [] dir_list_wdg = DirListWdg(paths=paths, base_dir=base_dir, location=location, ignore=ignore, depth=2) # cache the paths if rescan: paths = dir_list_wdg.get_paths() data['paths'] = paths session.set_json_value("data", data) session.commit() # add the paths found num_paths = dir_list_wdg.get_num_paths() found_wdg.add("Found: %s items" % num_paths) inner.add(dir_list_wdg) return top
def get_display(my): top = my.top top.add_color("background", "background") top.add_color("color", "color") top.add_style("width", "400px") top.add_class('spt_delete_stype_top') top.add_border() project_code = Project.get_project_code() # Note search types should only really be deleted if they were just # created search_type = my.kwargs.get("search_type") if not search_type: node_name = my.kwargs.get("node_name") if node_name: #project_code = Project.get_project_code() search_type = "%s/%s" % (project_code, node_name) assert search_type built_in_stypes = [ 'task', 'note', 'work_hour', 'login', 'login_group', 'schema', 'project', 'login_in_group', 'snapshot', 'file', 'trigger', 'spt_trigger', 'widget_config', 'custom_script', 'notification', 'notification_log', 'file_access', 'cache', 'exception_log', 'milestone', 'pipeline', 'pref_list', 'pref_setting', 'project_type', 'repo', 'remote_repo', 'search_sobject', 'sobject_list', 'ticket', 'db_resource', 'wdg_settings', 'status_log', 'debug_log', 'transaction_log', 'sobject_log' ] for tbl in built_in_stypes: if search_type == 'sthpw/%s' % tbl: top.add("sType [%s] is internal and cannot be deleted!" % search_type) top.add_style("font-size: 14px") top.add_style('padding: 20px') return top search_type_obj = SearchType.get(search_type) if not search_type: top.add("sType [%s] does not exist!" % search_type) top.add_style("font-size: 14px") top.add_style('padding: 20px') return top table = search_type_obj.get_table() db_val = search_type_obj.get_value('database') if db_val == '{project}': label = '' elif db_val == 'sthpw': label = 'built-in' else: label = 'project-specific' # warn if more than 1 sType point to the same table in the same project expr = "@GET(sthpw/search_type['table_name', '%s']['database', 'in', '{project}|%s']['namespace','%s'].search_type)" % ( table, project_code, project_code) rtn = Search.eval(expr) warning_msg = '' if len(rtn) > 1: warning_msg = 'Warning: There is more than 1 sType [%s] pointing to the same table [%s]. Deleting will affect both sTypes.' % ( ', '.join(rtn), table) title_wdg = DivWdg() top.add(title_wdg) title_wdg.add(IconWdg(icon=IconWdg.WARNING)) title_wdg.add("Delete %s sType: %s" % (label, search_type)) title_wdg.add_gradient("background", "background", -10, -10) title_wdg.add_style("padding: 5px") title_wdg.add_style("font-weight: bold") title_wdg.add_style("font-size: 14px") content = DivWdg() top.add(content) content.add_style("padding: 10px") if warning_msg: content.add(DivWdg(warning_msg, css='warning')) content.add("<br/>") content.add("This sType uses the table \"%s\" to store items.<br/>" % table) content.add("<br/>") search = Search(search_type) count = search.get_count() content.add("Number of items in the table: %s<br/>" % count) content.add("<br/>") search.add_column("id") sobjects = search.get_sobjects() if sobjects: items_search_type = sobjects[0].get_search_type() search_ids = [x.get_id() for x in sobjects] notes_search = Search("sthpw/note") notes_search.add_filters("search_id", search_ids) notes_search.add_filter("search_type", items_search_type) note_count = notes_search.get_count() cb = CheckboxWdg('related_types') cb.set_attr('value', 'sthpw/note') content.add(cb) content.add( SpanWdg("Number of related notes: %s" % note_count, css='small')) content.add(HtmlElement.br()) tasks_search = Search("sthpw/task") tasks_search.add_filters("search_id", search_ids) tasks_search.add_filter("search_type", items_search_type) task_count = tasks_search.get_count() cb = CheckboxWdg('related_types') cb.set_attr('value', 'sthpw/task') content.add(cb) content.add( SpanWdg("Number of related tasks: %s" % task_count, css='small')) content.add(HtmlElement.br()) snapshots_search = Search("sthpw/snapshot") snapshots_search.add_filters("search_id", search_ids) snapshots_search.add_filter("search_type", items_search_type) snapshot_count = snapshots_search.get_count() cb = CheckboxWdg('related_types') cb.set_attr('value', 'sthpw/snapshot') content.add(cb) content.add( SpanWdg("Number of related snapshots: %s" % snapshot_count, css='small')) content.add(HtmlElement.br()) pipelines_search = Search("sthpw/pipeline") pipelines_search.add_filter("search_type", search_type) pipeline_count = pipelines_search.get_count() cb = CheckboxWdg('related_types') cb.set_attr('value', 'sthpw/pipeline') content.add(cb) content.add( SpanWdg("Number of related pipelines: %s" % pipeline_count, css='small')) content.add(HtmlElement.br(2)) content.add( "<b>WARNING: Deleting the sType will delete all of these items.</b> " ) content.add("<br/>" * 2) content.add("Do you wish to continue deleting?") content.add("<br/>" * 2) button_div = DivWdg() button_div.add_styles('width: 300px; height: 50px') button = ActionButtonWdg(title="Delete") button_div.add(button) content.add(button_div) button.add_style("float: left") button.add_behavior({ 'type': 'click_up', 'search_type': search_type, 'cbjs_action': ''' spt.app_busy.show("Deleting sType"); var class_name = "tactic.ui.tools.DeleteSearchTypeCmd"; var ui_top = bvr.src_el.getParent(".spt_delete_stype_top"); var values = spt.api.Utility.get_input_values(ui_top); var kwargs = { 'search_type': bvr.search_type, 'values': values }; var server = TacticServerStub.get(); try { server.start({'title': 'Delete sType', 'description': 'Delete sType [' + bvr.search_type + ']'}); server.execute_cmd(class_name, kwargs); var top = bvr.src_el.getParent(".spt_popup"); spt.pipeline.remove_node(top.stype_node); // force a schema save spt.named_events.fire_event('schema|save', bvr) top.destroy(); server.finish(); } catch(e) { spt.alert(spt.exception.handler(e)); } spt.app_busy.hide(); spt.notify.show_message("Successfully deleted sType ["+bvr.search_type+"]"); ''' }) button = ActionButtonWdg(title="Cancel") button.add_style("float: left") button_div.add(button) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_popup"); top.destroy(); ''' }) return top
def get_display(self): top = self.top top.add_color("background", "background") top.add_class("spt_ingestion_shelf_top") #base_dir = self.kwargs.get("base_dir") #location = self.kwargs.get("location") base_dir = "/home/apache/Structures" location = "server" scan = ActionButtonWdg(title="Scan Files", tip="Scan Files") top.add(scan) scan.add_behavior({ 'type': 'click_up', 'base_dir': base_dir, 'location': location, 'cbjs_action': ''' var class_name = 'tactic.ui.tools.IngestionToolDirListWdg'; var kwargs = { base_dir: bvr.base_dir, location: bvr.location }; var top = bvr.src_el.getParent(".spt_ingestion_shelf_top"); var content = top.getElement(".spt_content"); spt.panel.load(content, class_name, kwargs); ''' }) scan.add_style("float: left") scan = ActionButtonWdg(title="Handled", tip="Show Handled Files") top.add(scan) scan.add_behavior({ 'type': 'click_up', 'base_dir': base_dir, 'location': location, 'cbjs_action': ''' var class_name = 'tactic.ui.tools.IngestionToolScanWdg'; var kwargs = { }; var top = bvr.src_el.getParent(".spt_ingestion_shelf_top"); var content = top.getElement(".spt_content"); spt.panel.load(content, class_name, kwargs); ''' }) scan.add_style("float: left") scan = ActionButtonWdg(title="Not Handled", tip="Show Files Not Handled") top.add(scan) scan.add_behavior({ 'type': 'click_up', 'base_dir': base_dir, 'location': location, 'cbjs_action': ''' var class_name = 'tactic.ui.tools.IngestionToolScanWdg'; var kwargs = { }; var top = bvr.src_el.getParent(".spt_ingestion_shelf_top"); var content = top.getElement(".spt_content"); spt.panel.load(content, class_name, kwargs); ''' }) top.add("<hr/>") content = DivWdg() top.add(content) content.add_style("height: 100%") content.add_style("padding: 10px") content.add_class("spt_content") content.add(" ") return top
def get_display(self): top = self.top self.set_as_panel(top) top.add_class("spt_delete_top") top.add_color("background", "background") top.add_color("color", "color") top.add_border() top.add_style("width: 400px") top.add_border() search_key = self.kwargs.get("search_key") search_keys = self.kwargs.get("search_keys") if search_key: sobject = Search.get_by_search_key(search_key) sobjects = [sobject] search_keys = [search_key] elif search_keys: sobjects = Search.get_by_search_keys(search_keys) sobject = sobjects[0] if not sobjects or not sobject: msg = "%s not found" %search_key return msg search_type = sobject.get_base_search_type() if search_type in ['sthpw/project', 'sthpw/search_object']: msg = 'You cannot delete these items with this tool' return msg self.search_keys = search_keys title = DivWdg() top.add(title) icon = IconWdg("WARNING", IconWdg.WARNING) icon.add_style("float: left") title.add(icon) if len(self.search_keys) > 1: title.add("Delete %s Items" % len(self.search_keys)) else: title.add("Delete Item [%s]" % (sobject.get_code())) title.add_style("font-size: 20px") title.add_style("font-weight: bold") title.add_style("padding: 10px") title.add("<hr/>") content = DivWdg() top.add(content) content.add_style("margin: 5px 10px 20px 10px") content.add("The item to be deleted has a number of dependencies as described below:<br/>", 'heading') # find all the relationships related_types = SearchType.get_related_types(search_type, direction='children') items_div = DivWdg() content.add( items_div ) items_div.add_style("padding: 10px") valid_related_ctr = 0 for related_type in related_types: if related_type == "*": print("WARNING: related_type is *") continue if related_type == search_type: continue if related_type in ['sthpw/search_object','sthpw/search_type']: continue item_div = self.get_item_div(sobjects, related_type) if item_div: items_div.add(item_div) valid_related_ctr += 1 if valid_related_ctr > 0: #icon = IconWdg("Note", "BS_NOTE") #icon.add_style("float: left") #content.add( icon ) content.add("<div><b>By selecting the above, the corresponding related items will be deleted as well.</b></div>") content.add("<br/>"*2) else: # changed the heading to say no dependencies content.add("The item to be deleted has no dependencies.<br/>", 'heading') num_items = len(self.search_keys) if num_items == 1: verb = "is 1 item" else: verb = "are %s items" % num_items content.add("There %s to be deleted" % verb) content.add("<br/>"*2) content.add("Do you wish to continue deleting?") content.add("<br/>"*3) button_div = DivWdg() button_div.add_class("spt_buttons") content.add(button_div) button_div.add_style('text-align: center') button = ActionButtonWdg(title="Delete", width=100, color="danger") button_div.add(button) button.add_style("display: inline-block") deleting_div = DivWdg() content.add(deleting_div) deleting_div.add("<img src='/context/icons/common/indicator_snake.gif'/>") deleting_div.add_class("spt_delete_msg") deleting_div.add(" Deleting ...") deleting_div.add_style("text-align: center") deleting_div.add_style("font-size: 16px") deleting_div.add_style("margin: 20px") deleting_div.add_style("display: none") on_complete = self.kwargs.get("on_complete") button.add_behavior( { 'type': 'click_up', 'search_keys': self.search_keys, 'on_complete': on_complete, 'cbjs_action': ''' spt.app_busy.show("Deleting"); //spt.notify.show_message("Deleting ..."); //var button_el = bvr.src_el.getParent(".spt_buttons"); //button_el.setStyle("display", "none"); var top = bvr.src_el.getParent(".spt_delete_top"); var values = spt.api.Utility.get_input_values(top); var class_name = "tactic.ui.tools.DeleteCmd"; var kwargs = { 'search_keys': bvr.search_keys, 'values': values }; var del_trigger = function() { // for fast table var tmps = spt.split_search_key(bvr.search_keys[0]) var tmps2 = tmps[0].split('?'); var del_st_event = "delete|" + tmps2[0]; var bvr_fire = {}; var input = {'search_keys': bvr.search_keys}; bvr_fire.options = input; spt.named_events.fire_event(del_st_event, bvr_fire); } var server = TacticServerStub.get(); server.execute_cmd(class_name, kwargs, null, { on_complete: function() { //spt.notify.show_message("Finshed deleting ..."); // run the post delete and destroy the popup var popup = bvr.src_el.getParent(".spt_popup"); if (popup.spt_on_post_delete) { popup.spt_on_post_delete(); } del_trigger(); spt.popup.destroy(popup); if (bvr.on_complete) { on_complete = function() { eval(bvr.on_complete); } on_complete(); } spt.app_busy.hide(); }, on_error: function(e) { spt.notify.show_message("Error on delete"); spt.alert(spt.exception.handler(e)); spt.app_busy.hide(); } } ); ''' } ) button = ActionButtonWdg(title="Cancel", width=100) button_div.add(button) button.add_style("display: inline-block") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_popup"); top.destroy(); ''' } ) content.add("<br clear='all'/>") return top
def get_display(self): top = self.top self.set_as_panel(top) top.add_class("spt_ingestion_top") top.add_color("background", "background", -5) self.data = {} rules_div = DivWdg() top.add(rules_div) rules_div.add_style("padding: 10px") rules_div.add("Rules: ") rules_select = SelectWdg("rule_code") rule_code = self.get_value('rule_code') if rule_code: rules_select.set_value(rule_code) rules_select.set_option("query", "config/ingest_rule|code|title") rules_select.add_empty_option("-- New --") rules_div.add(rules_select) rules_select.add_behavior({ 'type': 'change', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); value = bvr.src_el.value; var class_name = 'tactic.ui.tools.IngestionToolWdg'; spt.panel.load(top, class_name, {rule_code: value} ); ''' }) rules_div.add("<hr/>") # read from the database if rule_code: search = Search("config/ingest_rule") search.add_filter("code", rule_code) sobject = search.get_sobject() else: sobject = None if sobject: self.data = sobject.get_value("data") if self.data: self.data = jsonloads(self.data) session_code = self.kwargs.get("session_code") if session_code: session = Search.get_by_code("config/ingest_session", session_code) else: if sobject: session = sobject.get_related_sobject("config/ingest_session") print("sobject: ", sobject.get_code(), sobject.get_value("spt_ingest_session_code")) print("parent: ", session) else: session = None if not session: #session = SearchType.create("config/ingest_session") #session.set_value("code", "session101") #session.set_value("location", "local") ##session.set_value("base_dir", "C:") top.add("No session defined!!!") return top rule = "" filter = "" ignore = "" # get the base path if sobject: base_dir = sobject.get_value("base_dir") else: base_dir = '' #else: # base_dir = self.get_value("base_dir") #if not base_dir: # base_dir = '' if sobject: title = sobject.get_value("title") else: title = '' if sobject: code = sobject.get_value("code") else: code = '' file_list = self.get_value("file_list") scan_type = self.get_value("scan_type") action_type = self.get_value("action_type") rule = self.get_value("rule") if not rule: rule = base_dir # get the rule for this path checkin_mode = "dir" depth = 0 table = Table() rules_div.add(table) table.add_color("color", "color") from tactic.ui.input.text_input_wdg import TextInputWdg # add the title table.add_row() td = table.add_cell() td.add("Title: ") td = table.add_cell() text = TextInputWdg(name="title") td.add(text) if title: text.set_value(title) text.add_class("spt_title") text.add_style("width: 400px") #text.add_color("background", "background", -10) # add the optional code table.add_row() td = table.add_cell() td.add("Code (optional): ") td = table.add_cell() text = TextInputWdg(name="code") td.add(text) if code: text.set_value(code) text.set_readonly() text.add_color("background", "background", -10) text.add_class("spt_code") text.add_style("width: 400px") table.add_row() td = table.add_cell() td.add_style("height: 10px") td.add("<hr/>") table.add_row() td = table.add_cell() td.add("<b>Scan:</b><br/>") td.add( "The following information will be used to find the paths that will be operated on by the ingestion process<br/><br/>" ) # add a scan type table.add_row() td = table.add_cell() td.add("Type: ") select = SelectWdg("scan_type") select.add_class("spt_scan_type") td = table.add_cell() td.add(select) select.set_value(self.get_value("action")) labels = ['Simple List', 'Rule', 'Script'] values = ['list', 'rule', 'script'] select.set_option("values", values) select.set_option("labels", labels) if scan_type: select.set_value(scan_type) table.add_row() table.add_cell(" ") select.add_behavior({ 'type': 'change', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); value = bvr.src_el.value; var elements = top.getElements(".spt_scan_list"); for (var i = 0; i < elements.length; i++) { if (value == 'list') spt.show(elements[i]); else spt.hide(elements[i]); } var elements = top.getElements(".spt_scan_rule"); for (var i = 0; i < elements.length; i++) { if (value == 'rule') spt.show(elements[i]); else spt.hide(elements[i]); } var elements = top.getElements(".spt_scan_script"); for (var i = 0; i < elements.length; i++) { if (value == 'script') spt.show(elements[i]); else spt.hide(elements[i]); } ''' }) # add in a list of stuff tbody = table.add_tbody() tbody.add_class("spt_scan_list") if scan_type != 'list': tbody.add_style("display: none") tr = table.add_row() td = table.add_cell() td.add("List of files: ") td = table.add_cell() text = TextAreaWdg(name="file_list") td.add(text) text.add_style("width: 400px") #text.set_readonly() #text.add_color("background", "background", -10) text.set_value(file_list) table.close_tbody() # add rule scan mode tbody = table.add_tbody() tbody.add_class("spt_scan_rule") if scan_type != 'rule': tbody.add_style("display: none") # add the path tr = table.add_row() td = table.add_cell() td.add("Starting Path: ") td = table.add_cell() hidden = HiddenWdg("session_code", session.get_code()) td.add(hidden) text = TextInputWdg(name="base_dir") td.add(text) text.set_value(base_dir) text.add_style("width: 400px") #text.set_readonly() #text.add_color("background", "background", -10) text.set_value(base_dir) # add rule tr = table.add_row() td = table.add_cell() td.add("Tag Rule: ") td = table.add_cell() text = TextInputWdg(name="rule") td.add(text) text.add_style("width: 400px") text.set_value(rule) tr = table.add_row() td = table.add_cell() td.add("Filter: ") td = table.add_cell() text = TextWdg("filter") td.add(text) text.set_value(self.get_value("filter")) text.add_style("width: 400px") text.add_style("padding: 2px") text.add_style("-moz-border-radius: 5px") tr = table.add_row() td = table.add_cell() td.add("Ignore: ") td = table.add_cell() text = TextWdg("ignore") td.add(text) text.set_value(self.get_value("ignore")) text.set_value(ignore) text.add_style("width: 400px") text.add_style("padding: 2px") text.add_style("-moz-border-radius: 5px") table.add_row() td = table.add_cell() td.add("Validation script: ") td.add_style("vertical-align: top") td.add_style("padding-top: 5px") td = table.add_cell() text = TextInputWdg(name="validation_script") text.set_value(self.get_value("validation_script")) text.add_style("width: 400px") td.add(text) icon = IconButtonWdg(title='Edit Validation Script', icon=IconWdg.EDIT) icon.add_style("float: right") td.add(icon) icon.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.named_events.fire_event("show_script_editor"); var top = bvr.src_el.getParent(".spt_ingestion_top"); var values = spt.api.Utility.get_input_values(top, null, false); var kwargs = { script_path: values.validation_script } setTimeout( function() { spt.js_edit.display_script_cbk(evt, kwargs) }, 500 ); ''' }) table.close_tbody() # add the script path tbody = table.add_tbody() tbody.add_class("spt_scan_script") if scan_type != 'script': tbody.add_style("display: none") tr = table.add_row() td = table.add_cell() td.add("Script Path: ") td = table.add_cell() text = TextInputWdg(name="script_path") td.add(text) text.add_style("width: 400px") table.close_tbody() table.add_row() td = table.add_cell("<hr/>") table.add_row() td = table.add_cell() td.add("<b>Action</b><br/>") td.add( "The following information define the actions that will be used on each matched path<br/><br/>" ) # pick the type of action table.add_row() td = table.add_cell() td.add("Type: ") select = SelectWdg("action_type") td = table.add_cell() td.add(select) labels = ['Checkin', 'Ignore'] values = ['checkin', 'ignore'] select.set_option("values", values) select.set_option("labels", labels) select.add_empty_option("-- Select --") if action_type: select.set_value(action_type) select.add_behavior({ 'type': 'change', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); value = bvr.src_el.value; var elements = top.getElements(".spt_action_ignore"); for (var i = 0; i < elements.length; i++) { if (value == 'ignore') spt.show(elements[i]); else spt.hide(elements[i]); } var elements = top.getElements(".spt_action_checkin"); for (var i = 0; i < elements.length; i++) { if (value == 'checkin') spt.show(elements[i]); else spt.hide(elements[i]); } ''' }) table.add_row() td = table.add_cell("<br/>") # add the script path tbody = table.add_tbody() tbody.add_class("spt_action_checkin") if action_type != 'checkin': tbody.add_style("display: none") # add the checkin type table.add_row() td = table.add_cell() td.add("Action: ") select = SelectWdg("action") td = table.add_cell() td.add(select) select.set_value(self.get_value("action")) labels = ['File Checkin', 'Directory Checkin', 'Sequence Checkin'] values = ['file', 'directory', 'sequence', 'ignore'] select.set_option("values", values) select.set_option("labels", labels) table.add_row() td = table.add_cell() td.add("Mode: ") select = SelectWdg("mode") td = table.add_cell() td.add(select) labels = ['Copy', 'Move', 'In Place'] values = ['copy', 'move', 'inplace'] select.set_option("values", values) select.set_option("labels", labels) # add the search_type table.add_row() td = table.add_cell() td.add("sType: ") td = table.add_cell() select = SelectWdg("search_type") td.add(select) search_types = Project.get().get_search_types() values = [x.get_value("search_type") for x in search_types] select.set_option("values", values) search_type = self.kwargs.get("search_type") if search_type: select.set_value(search_type) # add the search_type table.add_row() td = table.add_cell() td.add("Context: ") td = table.add_cell() select = SelectWdg("context") td.add(select) select.set_option("values", ['publish', 'by rule', 'custom']) # add extra values extra_div = DivWdg() text = TextWdg("extra_name") text.add_attr("spt_is_multiple", "true") extra_div.add(text) extra_div.add(" = ") text = TextWdg("extra_value") extra_div.add(text) text.add_attr("spt_is_multiple", "true") template_div = DivWdg() text = TextWdg("extra_name") text.add_attr("spt_is_multiple", "true") template_div.add(text) template_div.add(" = ") text = TextWdg("extra_value") template_div.add(text) text.add_attr("spt_is_multiple", "true") table.close_tbody() table.add_row() td = table.add_cell("<br/>") table.add_row() td = table.add_cell() td.add("Extra Keywords: ") td.add_style("vertical-align: top") td.add_style("padding-top: 5px") td = table.add_cell() text = TextWdg("keywords") text.add_style("width: 300px") td.add(text) table.add_row() td = table.add_cell() td.add("Extra Values: ") td.add_style("vertical-align: top") td.add_style("padding-top: 5px") td = table.add_cell() extra_list = DynamicListWdg() td.add(extra_list) extra_list.add_item(extra_div) extra_list.add_template(template_div) table.add_row() table.add_cell(" ") table.add_row() td = table.add_cell() td.add("Process script: ") td.add_style("vertical-align: top") td.add_style("padding-top: 5px") td = table.add_cell() text = TextWdg("process_script") text.add_style("width: 300px") td.add(text) text.set_value(self.get_value("process_script")) icon = IconButtonWdg(title='Edit Process Script', icon=IconWdg.EDIT) icon.add_style("float: right") td.add(icon) icon.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.named_events.fire_event("show_script_editor"); var top = bvr.src_el.getParent(".spt_ingestion_top"); var values = spt.api.Utility.get_input_values(top, null, false); var kwargs = { script_path: values.process_script } // need to wait for this setTimeout( function() { spt.js_edit.display_script_cbk(evt, kwargs) }, 500 ); ''' }) table.add_row() td = table.add_cell() td.add("Custom Naming: ") td.add_style("vertical-align: top") td.add_style("padding-top: 5px") td = table.add_cell() text = TextWdg("naming") text.add_style("width: 300px") td.add(text) table.add_row() td = table.add_cell() #td.add("<br clear='all'/>") td.add("<hr/>") behavior = { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); var values = spt.api.Utility.get_input_values(top, null, false); spt.app_busy.show("Scanning ...", values.base_dir); var class_name = 'tactic.ui.tools.IngestionProcessWdg'; var server = TacticServerStub.get(); values.mode = bvr.mode; values.is_local = 'true'; // scan client side if (values.is_local == 'true') { var base_dir = values.base_dir; var applet = spt.Applet.get(); var files = applet.list_recursive_dir(base_dir); // turn into a string var files_in_js = []; for (var i = 0; i < files.length; i++) { var file = files[i].replace(/\\\\/g, "/"); files_in_js.push( file ); } values.files = files_in_js; values.base_dir = base_dir; /* var server = TacticServerStub.get(); var handoff_dir = server.get_handoff_dir(); var applet = spt.Applet.get(); for (var i = 0; i < files_in_js.length; i++) { try { var parts = files_in_js[i].split("/"); var filename = parts[parts.length-1]; spt.app_busy.show("Copying files to handoff", filename); applet.copy_file(files_in_js[i], handoff_dir+"/"+filename); } catch(e) { log.error(e); } } */ } var info_el = top.getElement(".spt_info"); spt.panel.load(info_el, class_name, values); spt.app_busy.hide(); ''' } # Save button button = ActionButtonWdg(title="Save", tip="Save Rule") td.add(button) button.add_style("float: right") behavior['mode'] = 'save' button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); var values = spt.api.Utility.get_input_values(top, null, false); spt.app_busy.show("Saving ..."); var class_name = 'tactic.command.CheckinRuleSaveCmd'; var server = TacticServerStub.get(); server.execute_cmd(class_name, values); spt.panel.refresh(top, {}); spt.app_busy.hide(); ''' }) # Scan button button = ActionButtonWdg(title="Scan", tip="Click to Scan") td.add(button) button.add_style("float: left") # set a limit #limit = TextWdg("limit") #td.add(limit) #text.add_style("float: left") behavior = behavior.copy() behavior['mode'] = 'scan' button.add_behavior(behavior) # Test button button = ActionButtonWdg(title="Test", tip="Do a test of this rule") td.add(button) behavior = behavior.copy() behavior['mode'] = 'test' button.add_behavior(behavior) button.add_style("float: left") # Ingest button button = ActionButtonWdg(title="Ingest", tip="Click to start ingesting") td.add(button) behavior = behavior.copy() behavior['mode'] = 'checkin' button.add_behavior(behavior) table.add_behavior({ 'type': 'listen', 'event_name': 'file_browser|select', 'cbjs_action': ''' var dirname = bvr.firing_data.dirname; var top = bvr.src_el.getParent(".spt_ingestion_top"); var kwargs = { base_dir: dirname }; spt.panel.load(top, top.getAttribute("spt_class_name"), kwargs); ''' }) top.add(self.get_info_wdg()) return top
def get_error_wdg(my): div = DivWdg() error_div = DivWdg() error_div.add("Error %s - Permission Denied" % my.status) div.add(error_div) error_div.add_style("font-size: 16px") error_div.add_style("font-weight: bold") error_div.add_style("width: 97%") error_div.add_gradient("background", "background") error_div.add_border() error_div.add_style("margin-left: 5px") error_div.add_style("margin-top: -10px") div.add("<br/>") span = DivWdg() #span.add_color("color", "color") span.add_style("color", "#FFF") if my.status == 403: span.add("<b>You have tried to access a url that is not permitted.</b>") else: span.add(HtmlElement.b(my.message)) span.add(HtmlElement.br(2)) web = WebContainer.get_web() root = web.get_site_root() span.add("Go back to the Main page for a list of valid projects") div.add(span) div.add(HtmlElement.br()) table = Table() div.add(table) table.add_row() table.add_style("margin-left: auto") table.add_style("margin-right: auto") from tactic.ui.widget import ActionButtonWdg button = ActionButtonWdg(title="Go to Main", tip='Click to go to main page') table.add_cell(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' document.location = '/projects'; ''' } ) button.add_style("margin-left: auto") button.add_style("margin-right: auto") button = ActionButtonWdg(title="Sign Out", tip='Click to Sign Out') table.add_cell(button) button.add_behavior( { 'type': 'click_up', 'login': web.get_user_name(), 'cbjs_action': ''' var server = TacticServerStub.get(); server.execute_cmd("SignOutCmd", {login: bvr.login} ); window.location.href='%s'; ''' % root } ) button.add_style("margin-left: auto") button.add_style("margin-right: auto") return div
def get_bottom_wdg(self): from tactic.ui.widget import ActionButtonWdg div = DivWdg() div.add_style("margin-top: 10px") back = ActionButtonWdg(title="< Back", tip="Go back to last page") div.add(back) back.add_class("spt_wizard_back") back.add_style("float: left") # FIXME: need to do this because set_style is not the same element as # add class back.add_behavior({ 'type': 'load', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_wizard_top"); var back = top.getElement(".spt_wizard_back"); back.setStyle("display", "none"); ''' }) back.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_wizard_top"); var pages = top.getElements(".spt_wizard_page"); var on_dots = top.getElements(".spt_wizard_on_dot"); var off_dots = top.getElements(".spt_wizard_off_dot"); // check boundary if (pages[0].hasClass("spt_wizard_selected")) { return; } var selected_index = 0; for (var i = 0; i < pages.length; i++) { var page = pages[i]; var on_dot = on_dots[i]; var off_dot = off_dots[i]; if (page.hasClass("spt_wizard_selected")) { page.removeClass("spt_wizard_selected"); selected_index = i; } page.setStyle("display", "none"); on_dot.setStyle("display", "none"); off_dot.setStyle("display", ""); } if (selected_index == 1) { var back = top.getElement(".spt_wizard_back"); back.setStyle("display", "none"); } if (selected_index == pages.length-1) { var next = top.getElement(".spt_wizard_next"); next.setStyle("display", ""); } var page = pages[selected_index-1]; page.setStyle("display", ""); page.addClass("spt_wizard_selected"); var on_dot = on_dots[selected_index-1]; var off_dot = off_dots[selected_index-1]; on_dot.setStyle("display", ""); off_dot.setStyle("display", "none"); ''' }) if self.submit_button: submit = self.submit_button else: submit_title = self.kwargs.get("submit_title") command = self.kwargs.get("command") script = self.kwargs.get("script") jsscript = self.kwargs.get("jsscript") if not submit_title: submit_title = "Submit" submit = ActionButtonWdg(title="%s >>" % submit_title, tip=submit_title) submit.add_class("spt_wizard_submit") submit.add_behavior({ 'type': 'click_up', 'command': command, 'script': script, 'jsscript': jsscript, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_wizard_top"); var values = spt.api.Utility.get_input_values(top); var server = TacticServerStub.get(); try { if (bvr.command) { spt.app_busy.show("Executing ...", ""); server.execute_cmd(bvr.command, values); } else if (bvr.jsscript) { var values = spt.api.get_input_values(top, null, false); spt.CustomProject.run_script_by_path(bvr.jsscript, values); } else if (bvr.script) { var values = spt.api.get_input_values(top, null, false); server.execute_python_script(bvr.script, {values:values}); } else { alert("No script or command defined"); } } catch(e) { console.log(e); var xml = spt.parse_xml(e); var node = xml.getElementsByTagName("string")[0]; if (node) { var error = node.textContent; spt.error("Error: " + error); spt.app_busy.hide(); } else { alert(e); } throw(e); } spt.app_busy.hide(); ''' }) div.add(submit) submit.add_style("float: right") next = ActionButtonWdg(title="Next >", tip="Go to next page") div.add(next) next.add_class("spt_wizard_next") next.add_style("float: right") next.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_wizard_top"); var pages = top.getElements(".spt_wizard_page"); var on_dots = top.getElements(".spt_wizard_on_dot"); var off_dots = top.getElements(".spt_wizard_off_dot"); // check boundary if (pages[pages.length-1].hasClass("spt_wizard_selected")) { return; } var selected_index = 0; for (var i = 0; i < pages.length; i++) { var page = pages[i]; var on_dot = on_dots[i]; var off_dot = off_dots[i]; if (page.hasClass("spt_wizard_selected")) { page.removeClass("spt_wizard_selected"); selected_index = i; } page.setStyle("display", "none"); on_dot.setStyle("display", "none"); off_dot.setStyle("display", ""); } if (selected_index == pages.length-2) { var next = top.getElement(".spt_wizard_next"); next.setStyle("display", "none"); } if (selected_index == 0) { var back = top.getElement(".spt_wizard_back"); back.setStyle("display", ""); } var page = pages[selected_index+1]; page.setStyle("display", ""); page.addClass("spt_wizard_selected"); var on_dot = on_dots[selected_index+1]; var off_dot = off_dots[selected_index+1]; on_dot.setStyle("display", ""); off_dot.setStyle("display", "none"); ''' }) div.add("<br clear='all'/>") return div
def get_buttons_wdg(my): button_div = DivWdg() button = ActionButtonWdg(title='Run') button_div.add(button) button.add_style("float: left") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_script_editor_top"); var code = top.getElement(".spt_code").value; var folder = top.getElement(".spt_folder").value; var title = top.getElement(".spt_title").value; var language = top.getElement(".spt_language").value; spt.ace_editor.set_editor_top(top); var editor = spt.ace_editor.editor; var value = editor.getSession().toString(); try { if (language == 'javascript') { eval(value); } else if (language == 'expression') { var server = TacticServerStub.get(); var ret_val; ret_val = server.eval(value); if (ret_val && ret_val.length) { for (var i = 0; i < ret_val.length; i++) { log.critical(ret_val[i]); } } else { log.critical(ret_val); } } else if (language == 'python') { var path = folder + "/" + title; var server = TacticServerStub.get(); var info = server.execute_python_script(path); log.critical(info); } else { var ok = function() { eval(value);} spt.confirm("Please set the language of this script. It's assumed to be javascript if left blank. Continue to run?", ok, null); } } catch(e) { spt.error(spt.exception.handler(e)); } ''' } ) button = ActionButtonWdg(title='Save') button_div.add(button) button.add_style("float: left") button.add_behavior( { 'type': 'click_up', 'editor_id': my.unique_id, 'cbjs_action': ''' /* if (!has_changes(bvr)) { spt.alert("No changes have been made"); return; } */ var top = bvr.src_el.getParent(".spt_script_editor_top"); spt.app_busy.show("Saving Script ..."); setTimeout(function() { spt.ace_editor.set_editor_top(top); spt.script_editor.save_script_cbk(evt, bvr); spt.app_busy.hide(); }, 10); ''' } ) button = ActionButtonWdg(title='Clear') button_div.add(button) button.add_style("float: left") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.api.Utility.clear_inputs( bvr.src_el.getParent('.spt_js_editor') ); var top = bvr.src_el.getParent(".spt_script_editor_top"); spt.ace_editor.set_editor_top(top); var editor = spt.ace_editor.editor; var document = editor.getSession().getDocument() document.setValue(""); ''' } ) button = ActionButtonWdg(title='Resize') #button_div.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var editor = spt.ace_editor.editor; var editor_id = spt.ace_editor.editor_id; $(editor_id).setStyle("width", "1000px"); $(editor_id).setStyle("height", "800px"); editor.resize(); ''' } ) return button_div
def get_display(my): data = my.kwargs.get('kwargs') if data: data = jsonloads(data) my.kwargs.update(data) my.search_type = my.kwargs.get("search_type") my.x_axis = my.kwargs.get("x_axis") if not my.x_axis: my.x_axis = 'code' my.y_axis = my.kwargs.get("y_axis") if type(my.y_axis) == types.ListType: my.y_axis = "|".join( my.y_axis ) my.chart_type = my.kwargs.get("chart_type") if not my.chart_type: my.chart_type = 'bar' # get any search keys if any are passed in my.search_keys = my.kwargs.get("search_keys") top = DivWdg() top.add_class("spt_chart_builder") top.add_color("background", "background") top.add_border() from tactic.ui.app import HelpButtonWdg help_button = HelpButtonWdg(alias='charting') top.add( help_button ) help_button.add_style("float: right") project = Project.get() search_types = project.get_search_types(include_sthpw=True) search_types = [x.get_value("search_type") for x in search_types] build_div = DivWdg() from pyasm.widget import SwapDisplayWdg swap_wdg = SwapDisplayWdg.get_triangle_wdg() swap_script = swap_wdg.get_swap_script() build_div.add(swap_wdg) build_div.add("<b>Chart Specifications</b>") build_div.add_style("margin-bottom: 5px") build_div.add_style("height: 25px") build_div.add_style("padding-top: 5px") build_div.add_gradient("background", "background", -10) build_div.add_color("color", "color") build_div.add_class("hand") build_div.add_class("SPT_DTS") top.add(build_div) build_div.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_chart_builder"); var spec = top.getElement(".spt_chart_spec"); //spt.api.toggle_show_hide(spec); spt.toggle_show_hide(spec); %s; ''' % swap_script } ) spec_div = DivWdg() spec_div.add_color("color", "color3") spec_div.add_color("background", "background3") spec_div.add_class("spt_chart_spec") spec_div.add_border() spec_div.add_style("padding: 10px") spec_div.add_style("margin: 5px") spec_div.add_style("display: none") top.add(spec_div) table = Table() table.add_color("color", "color3") spec_div.add(table) # add the search type selector table.add_row() table.add_cell("Search Type: ") search_type_div = DivWdg() search_type_select = TextWdg("search_type") search_type_select.set_value(my.search_type) #search_type_select.set_option("values", search_types) search_type_div.add(search_type_select) table.add_cell(search_type_div) # add the chart type selector table.add_row() table.add_cell("Chart Type: ") type_div = DivWdg() #type_div.add_style("padding: 3px") type_select = SelectWdg("chart_type") type_select.set_option("values", "line|bar|area") if my.chart_type: type_select.set_value(my.chart_type) type_div.add(type_select) table.add_cell(type_div) # add the chart type selector table.add_row() table.add_cell("X-Axis: ") # need to find all expression widgets or use get_text_value()? x_axis_div = DivWdg() x_axis_text = TextWdg("x_axis") x_axis_text.set_value("code") x_axis_div.add(x_axis_text) table.add_cell(x_axis_div) # add the chart type selector table.add_row() td = table.add_cell("Y-Axis: ") td.add_style("vertical-align: top") y_axis_div = DivWdg() #y_axis_text = TextWdg("y_axis") #if my.y_axis: # y_axis_text.set_value(my.y_axis) #y_axis_div.add(y_axis_text) td = table.add_cell(y_axis_div) # add in a list of entries from tactic.ui.container import DynamicListWdg list_wdg = DynamicListWdg() for value in my.y_axis.split("|"): item = TextWdg("y_axis") item.set_value(value, set_form_value=False) list_wdg.add_item(item) y_axis_div.add(list_wdg) spec_div.add("<br/>") from tactic.ui.widget import ActionButtonWdg button = ActionButtonWdg(title="Refresh") spec_div.add(button) spec_div.add(HtmlElement.br(2)) button.add_style("float: left") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_chart_builder"); var chart = top.getElement(".spt_chart"); var values = spt.api.get_input_values(top); //var values = spt.api.Utility.get_input_values(top); spt.panel.refresh(chart, values); ''' } ) #TODO: provide a field for user to type in the chart name """ button = ActionButtonWdg(title="Save") spec_div.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_chart_builder"); var chart = top.getElement(".spt_chart"); var values = spt.api.get_input_values(top); var login = '******'; var search_type = 'SideBarWdg'; var side_bar_view = 'project_view'; var unique_el_name = 'chart_test' var kwargs = {}; kwargs['login'] = null; //if (save_as_personal) // kwargs['login'] = login; kwargs['class_name'] = 'tactic.ui.chart.ChartBuilderWdg'; var display_options = {}; display_options['search_type'] = 'prod/asset' kwargs['display_options'] = display_options; kwargs['unique'] = true; //if (new_title) // kwargs['element_attrs'] = {'title': new_title}; var server = TacticServerStub.get() server.add_config_element(search_type, side_bar_view, unique_el_name, kwargs); spt.panel.refresh("side_bar"); ''' } ) """ width = '600px' kwargs = { 'y_axis': my.y_axis, 'chart_type': my.chart_type, 'search_type': my.search_type, 'width': width, 'search_keys': my.search_keys } chart_div = DivWdg() chart = BarChartWdg(**kwargs) chart_div.add(chart) top.add(chart_div) #from chart2_wdg import SampleSObjectChartWdg #chart = SampleSObjectChartWdg(**kwargs) #chart_div.add(chart) return top
def get_session_wdg(self): div = DivWdg() div.add_style("width: 150px") search = Search("config/ingest_rule") rules = search.get_sobjects() add = ActionButtonWdg(title="+", tip="Add new rule", size='small') div.add(add) add.add_style("margin-top: -6px") add.add_behavior( { 'type': 'click_up', 'session_code': self.session.get_code(), 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); spt.tab.set_tab_top(top); var class_name = 'tactic.ui.tools.IngestionToolWdg'; var kwargs = { session_code: bvr.session_code }; spt.tab.select("rules"); spt.tab.load_selected("rules", "Rules", class_name, kwargs); ''' } ) add.add_style("float: right") div.add("<b>Rules</b><hr/>") if not rules: div.add("<br/><i>No rules found</i><br/>") for rule in rules: rule_code = rule.get_code() rule_title = rule.get_value("title") rule_div = DivWdg() div.add(rule_div) rule_div.add_style("padding: 3px") hover = rule_div.get_color("background", -10) rule_div.add_behavior( { 'type': 'hover', 'hover': hover, 'cbjs_action_over': ''' bvr.src_el.setStyle("background", bvr.hover); ''', 'cbjs_action_out': ''' bvr.src_el.setStyle("background", ""); ''' } ) rule_div.add_class("hand") checkbox = CheckboxWdg("whatever") rule_div.add(checkbox) rule_div.add(rule_title) rule_div.add_behavior( { 'type': 'click_up', 'rule_code': rule_code, 'session_code': self.session_code, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); spt.tab.set_tab_top(top); var class_name = 'tactic.ui.tools.IngestionToolWdg'; var kwargs = { location: 'server', rule_code: bvr.rule_code, session_code: bvr.session_code }; spt.tab.select("rules"); spt.tab.load_selected("rules", "Rules", class_name, kwargs); ''' } ) return div
def get_group_wdg(self, prev_sobj): if not self.is_preprocessed: self.preprocess() sobject = self.get_current_sobject() ref_sobj = self.get_ref_obj(sobject) self.current_ref_sobj = ref_sobj if not ref_sobj: return "Undetermined parent: [%s]" % SearchKey.get_by_sobject(sobject) widget = DivWdg() # add add button #from tactic.ui.widget import TextBtnWdg, TextBtnSetWdg #buttons_list = [] #buttons_list.append( { # 'label': '+', 'tip': 'Add Another Item', # 'bvr': { 'cbjs_action': "spt.dg_table.add_item_cbk(evt, bvr)" } #} ) #add_btn = TextBtnSetWdg( float="right", buttons=buttons_list, # spacing=6, size='small', side_padding=0 ) #widget.add(add_btn) from tactic.ui.widget import ActionButtonWdg button = ActionButtonWdg(title='+', tip='Add Another Item', size='small') widget.add(button) button.add_style("float: right") button.add_behavior( { 'type': 'click_up', 'cbjs_action': "spt.dg_table.add_item_cbk(evt, bvr)" } ) label = "Attach" label_option = self.get_option("label") if label_option: label = label_option table = Table() table.add_color("color", "color") table.add_row() search_key = sobject.get_search_key() # add a thumbe widget thumb = ThumbWdg() thumb.set_icon_size(40) thumb.set_sobject(ref_sobj) thumb.set_option('latest_icon', 'true') table.add_cell(thumb) # add the text description name_span = DivWdg(ref_sobj.get_code()) name_span.add_style('margin-left: 20px') table.add_cell(name_span) if ref_sobj.has_value("name"): name_span.add( " - " ) name_span.add( ref_sobj.get_value("name") ) #status = ref_sobj.get_value("status", no_exception=True) #if status: # span = SpanWdg("(status:%s)" % ref_sobj.get_value("status")) # table.add_cell(span) if ref_sobj.has_value("description"): description_wdg = ExpandableTextWdg("description") description_wdg.set_max_length(200) description_wdg.set_sobject(ref_sobj) td = table.add_cell( description_wdg ) td.add_style("padding-left: 15px") # FIXME: not sure about the layout here #if ref_sobj.has_value("pipeline_code"): # pipeline_code = ref_sobj.get_value("pipeline_code") # span = SpanWdg("(pipeline:%s)" % pipeline_code ) # td = table.add_cell(span) # td.add_style("padding-left: 15px") widget.add(table) return widget
def get_display(self): top = self.top top.add_color("background", "background") top.add_class("spt_ingestion_shelf_top") #base_dir = self.kwargs.get("base_dir") #location = self.kwargs.get("location") base_dir = "/home/apache/Structures" location = "server" scan = ActionButtonWdg(title="Scan Files", tip="Scan Files") top.add(scan) scan.add_behavior( { 'type': 'click_up', 'base_dir': base_dir, 'location': location, 'cbjs_action': ''' var class_name = 'tactic.ui.tools.IngestionToolDirListWdg'; var kwargs = { base_dir: bvr.base_dir, location: bvr.location }; var top = bvr.src_el.getParent(".spt_ingestion_shelf_top"); var content = top.getElement(".spt_content"); spt.panel.load(content, class_name, kwargs); ''' } ) scan.add_style("float: left") scan = ActionButtonWdg(title="Handled", tip="Show Handled Files") top.add(scan) scan.add_behavior( { 'type': 'click_up', 'base_dir': base_dir, 'location': location, 'cbjs_action': ''' var class_name = 'tactic.ui.tools.IngestionToolScanWdg'; var kwargs = { }; var top = bvr.src_el.getParent(".spt_ingestion_shelf_top"); var content = top.getElement(".spt_content"); spt.panel.load(content, class_name, kwargs); ''' } ) scan.add_style("float: left") scan = ActionButtonWdg(title="Not Handled", tip="Show Files Not Handled") top.add(scan) scan.add_behavior( { 'type': 'click_up', 'base_dir': base_dir, 'location': location, 'cbjs_action': ''' var class_name = 'tactic.ui.tools.IngestionToolScanWdg'; var kwargs = { }; var top = bvr.src_el.getParent(".spt_ingestion_shelf_top"); var content = top.getElement(".spt_content"); spt.panel.load(content, class_name, kwargs); ''' } ) top.add("<hr/>") content = DivWdg() top.add(content) content.add_style("height: 100%") content.add_style("padding: 10px") content.add_class("spt_content") content.add(" ") return top
def get_display(self): top = self.top self.set_as_panel(top) top.add_class("spt_checkin_dependency_top") top.add_color("background", "background") top.add_color("color", "color") top.add_style("width: 800px") title = DivWdg() top.add(title) title.add("Current Dependencies") title.add_color("color", "color3") title.add_color("background", "background3") title.add_style("font-size: 1.2em") title.add_style("font-weight: bold") title.add_style("padding: 10px 10px") # Not sure what to do with this yet search_key = self.kwargs.get("search_key") search_key = None snapshot_key = self.kwargs.get("snapshot_key") process = self.kwargs.get("process") if not process: process = "publish" if snapshot_key: snapshot = Search.get_by_search_key(snapshot_key) elif search_key: sobject = Search.get_by_search_key(search_key) snapshot = Snapshot.get_latest_by_sobject(sobject, process=process) else: snapshot = None #context = self.kwargs.get("context") #context = "publish/X6.tex" from tactic.ui.widget import ActionButtonWdg button = ActionButtonWdg(title="Browse") button.add_style("float: left") top.add(button) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var applet = spt.Applet.get(); var files = applet.open_file_browser(); alert(files); ''' }) from tactic.ui.widget import ActionButtonWdg button = ActionButtonWdg(title="Clipboard") button.add_style("float: left") top.add(button) button.add_behavior({ 'type': 'click_up', 'cbjs_action': r''' var server = TacticServerStub.get(); var items = server.eval("@SOBJECT(sthpw/clipboard['category','select']['login',$LOGIN])") var search_keys = spt.table.get_all_search_keys(); for (var i = 0; i < items.length; i++) { var item = items[i]; var search_key = item.search_type + "&code=" + item.search_code; search_keys.push(search_key); } var top = bvr.src_el.getParent(".spt_checkin_dependency_top"); top.setAttribute("spt_snapshot_keys", search_keys.join("|")) spt.panel.refresh(top); spt.tab.set_tab_top_from_child(bvr.src_el); var content = spt.tab.get_content("Dependency"); var activator = content.activator; activator.setAttribute("spt_depend_keys", search_keys.join("|")); ''' }) button = ActionButtonWdg(title="Remove") button.add_style("float: left") top.add(button) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_checkin_dependency_top"); var layout = top.getElement(".spt_layout"); spt.table.set_layout(layout); spt.table.remove_selected(); var search_keys = spt.table.get_all_search_keys(); alert(search_keys); spt.tab.set_tab_top_from_child(bvr.src_el); var content = spt.tab.get_content("Dependency"); var activator = content.activator; activator.setAttribute("spt_depend_keys", search_keys.join("|")); activator.setStyle("border", "solid 1px green"); ''' }) """ button = ActionButtonWdg(title="Attach") button.add_style("float: left") top.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_checkin_dependency_top"); var layout = top.getElement(".spt_layout"); spt.table.set_layout(layout); var search_keys = spt.table.get_selected_search_keys(); ''' } ) """ top.add("<br clear='all'/>") sobject_wdg = DivWdg() top.add(sobject_wdg) #text = TextInputWdg("search_type") #sobject_wdg.add(text) depend_keys = self.kwargs.get("depend_keys") if isinstance(depend_keys, basestring): depend_keys = depend_keys.split("|") if depend_keys: ref_snapshots = Search.get_by_search_keys(depend_keys) elif snapshot: # get the already existing snapshots ref_snapshots = snapshot.get_all_ref_snapshots(snapshot) else: ref_snapshots = [] snapshot_keys = self.kwargs.get("snapshot_keys") if snapshot_keys: snapshot_keys = snapshot_keys.split("|") extra_snapshots = Search.get_by_search_keys(snapshot_keys) for extra_snapshot in extra_snapshots: extra_snapshot = Snapshot.get_latest_by_sobject( extra_snapshot, process=process) if extra_snapshot: ref_snapshots.append(extra_snapshot) if not ref_snapshots: return top #print "ref: ", ref_snapshots search_type = "jobs/media" search_type = "sthpw/snapshot" from tactic.ui.panel import ViewPanelWdg panel = ViewPanelWdg( search_type=search_type, show_shelf=False, ) #layout='tile', panel.set_sobjects(ref_snapshots) top.add(panel) return top
def get_gear_menu(my): top = DivWdg() # FIXME: the gear menu widget should be here from tactic.ui.container import GearMenuWdg, Menu, MenuItem menu = Menu(width=180) menu_item = MenuItem(type="title", label="Actions") menu.add(menu_item) # create a new element menu_item = MenuItem(type="action", label="New Element") behavior = { "options": {"is_insert": "true", "search_type": my.search_type, "view": my.view}, "cbjs_action": """ var activator = spt.smenu.get_activator(bvr); var top = activator.getParent(".spt_view_manager_top"); var detail_panel = top.getElement(".spt_view_manager_detail"); var class_name = 'tactic.ui.manager.ElementDefinitionWdg'; var options = bvr.options var values = {}; spt.panel.load(detail_panel, class_name, options, values, false); """, } menu_item.add_behavior(behavior) menu.add(menu_item) menu_item = MenuItem(type="separator") menu.add(menu_item) # Show preview of the view menu_item = MenuItem(type="action", label="Show Preview") behavior = { "search_type": my.search_type, "view": my.view, "cbjs_action": """ var kwargs = { search_type: bvr.search_type, view: bvr.view }; var title = "Search Type: [" + bvr.search_type + "], View [" + bvr.view + "]"; spt.panel.load_popup(title, 'tactic.ui.panel.ViewPanelWdg', kwargs); """, } menu_item.add_behavior(behavior) menu.add(menu_item) # Show preview of the view menu_item = MenuItem(type="action", label="Show Full XML Config") behavior = { "search_type": my.search_type, "view": my.view, "cbjs_action": """ var kwargs = { search_type: 'config/widget_config', view: 'table', expression: "@SOBJECT(config/widget_config['search_type','"+bvr.search_type+"']['view','"+bvr.view+"'])", filter: [{}] }; var title = "Widget Config - ["+bvr.search_type+"] ["+bvr.view+"]"; spt.panel.load_popup(title, 'tactic.ui.panel.ViewPanelWdg', kwargs); """, } menu_item.add_behavior(behavior) menu.add(menu_item) menu_item = MenuItem(type="separator") menu.add(menu_item) # New view popup new_view_wdg = DivWdg() new_view_wdg.add_class("spt_new_view") new_view_wdg.add_style("display: none") new_view_wdg.add_style("position: absolute") new_view_wdg.add_color("background", "background") new_view_wdg.add_style("z-index: 100") new_view_wdg.add_border() new_view_wdg.set_round_corners() new_view_wdg.set_box_shadow() new_view_wdg.add_style("padding: 30px") new_view_wdg.add("New View Name: ") new_view_text = TextWdg("new_view") new_view_text.add_class("spt_new_view_text") new_view_wdg.add(new_view_text) new_view_wdg.add(HtmlElement.br(2)) # new_view_button = ProdIconButtonWdg('Save New View') new_view_button = ActionButtonWdg(title="Save", tip="Save New View") new_view_button.add_style("float: left") new_view_wdg.add(new_view_button) new_view_button.add_behavior( { "type": "click_up", "search_type": my.search_type, "cbjs_action": """ var top = bvr.src_el.getParent(".spt_view_manager_top"); var new_view_wdg = bvr.src_el.getParent(".spt_new_view"); var new_view_text = new_view_wdg.getElement(".spt_new_view_text"); var view = new_view_text.value; if (view != '') { var server = TacticServerStub.get() server.update_config(bvr.search_type, view, []); var values = { search_type: bvr.search_type, view: view }; spt.panel.refresh(top, values); spt.hide(new_view_wdg); } else { alert("Must supply view name"); } """, } ) # new_view_cancel_button = ProdIconButtonWdg('Cancel') new_view_cancel_button = ActionButtonWdg(title="Cancel", tip="Cancel Save") new_view_cancel_button.add_behavior( { "type": "click_up", "cbjs_action": """ var new_view_wdg = bvr.src_el.getParent(".spt_new_view"); spt.hide(new_view_wdg); """, } ) new_view_wdg.add(new_view_cancel_button) top.add(new_view_wdg) # TODO: to be implemented.. no more xx please! """ # Save to Project View menu_item = MenuItem(type='action', label='xx Save to Project View') behavior = { 'options': { 'search_type': 'SideBarWdg', 'view': 'project_view' }, 'cbjs_action': ''' spt.panel.load_popup('SideBar Section', 'tactic.ui.manager.SideBarSectionWdg', bvr.options); '''} menu_item.add_behavior(behavior) menu.add(menu_item) """ # Create a new view menu_item = MenuItem(type="action", label="Create New View") behavior = { "search_type": my.search_type, "view": my.view, "cbjs_action": """ var activator = spt.smenu.get_activator(bvr); var top = activator.getParent(".spt_view_manager_top"); var new_view_wdg = top.getElement(".spt_new_view"); spt.show(new_view_wdg); """, } menu_item.add_behavior(behavior) menu.add(menu_item) # Clear the current view menu_item = MenuItem(type="action", label="Clear View") behavior = { "options": {"is_insert": "true", "search_type": my.search_type, "view": my.view}, "cbjs_action": """ if (confirm("Are you sure you wih to clear this view?")) { var activator = spt.smenu.get_activator(bvr); var top = activator.getParent(".spt_view_manager_top"); var list_top = top.getElement(".spt_menu_item_list"); var elements = spt.side_bar.get_elements(bvr.view,list_top); for (var i=0; i<elements.length; i++) { var element = elements[i]; if (element.hasClass("spt_side_bar_dummy")) { continue; } element.destroy(); } } """, } menu_item.add_behavior(behavior) menu.add(menu_item) gear_menu = GearMenuWdg() gear_menu.add(menu) top.add(gear_menu) return top
def get_display(my): top = my.top top.add_class("spt_sign_in_top") top.add_color("background", "background") top.add_style("padding: 30px") top.add_style("width: 300px") icon = IconWdg("Not signed in", IconWdg.WARNING) top.add(icon) top.add("You are not signed into Perforce.") top.add("<br/>" * 2) table = Table() top.add(table) from tactic.ui.input import TextInputWdg, PasswordInputWdg table.add_row() td = table.add_cell("Port: ") td.add_style("width: 75px") text = TextInputWdg(name="port") td = table.add_cell(text) td.add_style("vertical-align: top") text.set_value("1666") table.add_row() td = table.add_cell("Login: "******"vertical-align: top") td.add_style("width: 75px") text = TextInputWdg(name="user") td = table.add_cell(text) td.add_style("vertical-align: top") user = Environment.get_user_name() text.set_value(user) table.add_row() td = table.add_cell("Password: "******"vertical-align: top") text = PasswordInputWdg(name="password") table.add_cell(text) tr = table.add_row() table.add_row_cell(" ") tr = table.add_row() tr.add_class("spt_workspaces") #tr.add_style("display: none") td = table.add_cell("Workspace: ") td.add_style("vertical-align: top") workspaces = my.kwargs.get("workspaces") td = table.add_cell() button = ActionButtonWdg(width='55', title="Lookup") td.add(button) button.add_style("float: right") button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' try { var workspaces = spt.scm.get_workspaces(); var clients = []; for (var i = 0; i < workspaces.length; i++) { clients.push(workspaces[i].client); } clients = clients.join("|"); var kwargs = { workspaces: clients } spt.scm.show_login(kwargs); } catch(e) { spt.scm.signout_user(); spt.scm.show_login(); } ''' }) if not workspaces: text = TextInputWdg(name="workspace") text.add_style("width: 165px") td.add(text) else: select = SelectWdg("workspace") td.add(select) select.set_option("values", workspaces) top.add("<br/>" * 2) button = ActionButtonWdg(title="Sign In >>", size='medium') top.add(button) button.add_style("float: right") button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_sign_in_top"); var values = spt.api.get_input_values(top); var port = values.port[0]; var user = values.user[0]; var password = values.password[0]; var client = values.workspace[0]; if (!port) { alert("No port specified"); return; } if (!user) { alert("No user specified"); return; } if (!client) { alert("No workspace specified"); return; } // login in user spt.scm.port = port; spt.scm.user = user; spt.scm.password = password; // test the connection var ping = spt.scm.ping(); if (ping != "OK") { alert("Cannot connect to Perforce") spt.scm.signout_user(); spt.scm.show_login(); } else { spt.scm.client = client; // close the popup var popup = bvr.src_el.getParent(".spt_popup"); if (popup) { spt.popup.destroy(popup); } // NOTE: this is global: find a check-in widget and refresh var checkin_el = $(document.body).getElement(".spt_checkin_top"); spt.panel.refresh(checkin_el); } ''' }) top.add("<br/>" * 2) return top
def get_bottom_wdg(my): from tactic.ui.widget import ActionButtonWdg div = DivWdg() back = ActionButtonWdg(title="< Back", tip="Go back to last page") div.add(back) back.add_class("spt_wizard_back") back.add_style("float: left") # FIXME: need to do this because set_style is not the same element as # add class back.add_behavior( { 'type': 'load', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_wizard_top"); var back = top.getElement(".spt_wizard_back"); back.setStyle("display", "none"); ''' } ) back.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_wizard_top"); var pages = top.getElements(".spt_wizard_page"); var on_dots = top.getElements(".spt_wizard_on_dot"); var off_dots = top.getElements(".spt_wizard_off_dot"); // check boundary if (pages[0].hasClass("spt_wizard_selected")) { return; } var selected_index = 0; for (var i = 0; i < pages.length; i++) { var page = pages[i]; var on_dot = on_dots[i]; var off_dot = off_dots[i]; if (page.hasClass("spt_wizard_selected")) { page.removeClass("spt_wizard_selected"); selected_index = i; } page.setStyle("display", "none"); on_dot.setStyle("display", "none"); off_dot.setStyle("display", ""); } if (selected_index == 1) { var back = top.getElement(".spt_wizard_back"); back.setStyle("display", "none"); } if (selected_index == pages.length-1) { var next = top.getElement(".spt_wizard_next"); next.setStyle("display", ""); } var page = pages[selected_index-1]; page.setStyle("display", ""); page.addClass("spt_wizard_selected"); var on_dot = on_dots[selected_index-1]; var off_dot = off_dots[selected_index-1]; on_dot.setStyle("display", ""); off_dot.setStyle("display", "none"); ''' } ) if my.submit_button: submit = my.submit_button else: command = my.kwargs.get("command") submit_title = my.kwargs.get("submit_title") if not submit_title: submit_title = "Submit" submit = ActionButtonWdg(title="%s >>" % submit_title, tip=submit_title) submit.add_behavior( { 'type': 'click_up', 'command': command, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_wizard_top"); var values = spt.api.Utility.get_input_values(top); spt.app_busy.show("Executing ...", ""); var server = TacticServerStub.get(); try { server.execute_cmd(bvr.command, values); } catch(e) { var xml = spt.parse_xml(e); var node = xml.getElementsByTagName("string")[0]; var error = node.textContent; spt.error("Error: " + error); spt.app_busy.hide(); throw(e); } ''' } ) div.add(submit) submit.add_style("float: right") next = ActionButtonWdg(title="Next >", tip="Go to next page") div.add(next) next.add_class("spt_wizard_next") next.add_style("float: right") next.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_wizard_top"); var pages = top.getElements(".spt_wizard_page"); var on_dots = top.getElements(".spt_wizard_on_dot"); var off_dots = top.getElements(".spt_wizard_off_dot"); // check boundary if (pages[pages.length-1].hasClass("spt_wizard_selected")) { return; } var selected_index = 0; for (var i = 0; i < pages.length; i++) { var page = pages[i]; var on_dot = on_dots[i]; var off_dot = off_dots[i]; if (page.hasClass("spt_wizard_selected")) { page.removeClass("spt_wizard_selected"); selected_index = i; } page.setStyle("display", "none"); on_dot.setStyle("display", "none"); off_dot.setStyle("display", ""); } if (selected_index == pages.length-2) { var next = top.getElement(".spt_wizard_next"); next.setStyle("display", "none"); } if (selected_index == 0) { var back = top.getElement(".spt_wizard_back"); back.setStyle("display", ""); } var page = pages[selected_index+1]; page.setStyle("display", ""); page.addClass("spt_wizard_selected"); var on_dot = on_dots[selected_index+1]; var off_dot = off_dots[selected_index+1]; on_dot.setStyle("display", ""); off_dot.setStyle("display", "none"); ''' } ) div.add("<br clear='all'/>") return div
def get_display(my): my.sobject = my.kwargs.get("sobject") search_key = my.sobject.get_search_key() top = DivWdg() top.add_class("spt_checkin_publish") top.add_style("padding: 10px") margin_top = '60px' top.add_style("margin-top", margin_top) top.add_style("position: relative") current_changelist = WidgetSettings.get_value_by_key( "current_changelist") current_branch = WidgetSettings.get_value_by_key("current_branch") current_workspace = WidgetSettings.get_value_by_key( "current_workspace") top.add("Branch: %s<br/>" % current_branch) top.add("Changelist: %s<br/>" % current_changelist) top.add("Workspace: %s<br/>" % current_workspace) top.add("<br/>") checked_out_div = DivWdg() checkbox = CheckboxWdg("editable") top.add(checked_out_div) checkbox.add_class("spt_checkin_editable") checked_out_div.add(checkbox) checked_out_div.add("Leave files editable") top.add("<br/>") top.add("Publish Description<br/>") text = TextAreaWdg("description") # this needs to be set or it will stick out to the right text.add_style("width: 220px") text.add_class("spt_checkin_description") top.add(text) # add as a note note_div = DivWdg() top.add(note_div) note_div.add_class("spt_add_note") checkbox = CheckboxWdg("add_note") web = WebContainer.get_web() browser = web.get_browser() if browser in ['Qt']: checkbox.add_style("margin-top: -4px") checkbox.add_style("margin-right: 3px") note_div.add_style("margin-top: 3px") checkbox.add_class("spt_checkin_add_note") note_div.add(checkbox) note_div.add("Also add as note") top.add("<br/><br/>") button = ActionButtonWdg(title="Check-in", icon=IconWdg.PUBLISH, size='medium') top.add(button) my.repo_type = 'perforce' if my.repo_type == 'perforce': # the depot is set per project (unless overridden) project = my.sobject.get_project() depot = project.get_value("location", no_exception=True) if not depot: depot = project.get_code() asset_dir = Environment.get_asset_dir() sandbox_dir = Environment.get_sandbox_dir() changelist = WidgetSettings.get_value_by_key("current_changelist") button.add_behavior({ 'type': 'click_up', 'depot': depot, 'changelist': changelist, 'sandbox_dir': sandbox_dir, 'search_key': search_key, 'cbjs_action': ''' var paths = spt.checkin.get_selected_paths(); spt.app_busy.show("Checking in "+paths.length+" file/s into Perforce"); var top = bvr.src_el.getParent(".spt_checkin_top"); var description = top.getElement(".spt_checkin_description").value; var add_note = top.getElement(".spt_checkin_add_note").value; var editable = top.getElement(".spt_checkin_editable").value; if (editable == 'on') { editable = true; } else { editable = false; } var process = top.getElement(".spt_checkin_process").value; // check into TACTIC var server = TacticServerStub.get(); var revisions = []; server.start({description: "File Check-in"}); try { var top = bvr.src_el.getParent(".spt_checkin_top"); var el = top.getElement(".spt_mode"); var mode = el.value; // check-in the changelist var changelist = 'default'; if (mode == 'changelist') { var scm_info = spt.scm.run("commit_changelist", [changelist, description]); for ( var i = 1; i < scm_info.length-1; i++) { // the first item is the changelist number //console.log(scm_info[i]); var action = scm_info[i]; revision = action.rev; revisions.push(revision); // Do an inplace check-in into TACTIC var path = action.depotFile; var parts = path.split("/"); var filename = parts[parts.length-1]; var context = process + "/" + filename; var snapshot = server.simple_checkin(bvr.search_key, context, path, {description: description, mode: "perforce", version: revision} ); } } else { // check in all of the files for ( var i = 0; i < paths.length; i++) { var path = paths[i]; var scm_info = spt.scm.run("commit_file", [path, description, editable]); // the first item is the changelist number var action = scm_info[1]; revision = action.rev; revisions.push(revision); var parts = path.split("/"); var filename = parts[parts.length-1]; var context = process + "/" + filename; //path = path.replace(bvr.sandbox_dir, "//"+bvr.depot); // NOTE: this assumes project == depot path = path.replace(bvr.sandbox_dir, "//"); // Do an inplace check-in into TACTIC var snapshot = server.simple_checkin(bvr.search_key, context, path, {description: description, mode: "perforce", version: revision} ); } } if (add_note == 'on') { var note = []; note.push('CHECK-IN'); for (var i = 0; i < paths.length; i++) { var parts = paths[i].split("/"); var filename = parts[parts.length-1]; note.push(filename+' (v'+revisions[i]+')'); } note.push(': '); note.push(description); note = note.join(" "); server.create_note(bvr.search_key, note, {process: process}); } server.finish({description: "File Check-in ["+paths.length+" file/s]"}); spt.panel.refresh(top); } catch(e) { spt.error("Error detected: " + e.msg) //console.log(e); server.abort(); } spt.app_busy.hide(); ''' }) else: button.add_behavior(behavior) button.add_style("margin-right: auto") button.add_style("margin-left: auto") button.add_style("margin-top: 20px") button.add_style("margin-bottom: 20px") top.add("<br clear='all'/>") top.add("<hr/>") hidden = HiddenWdg("checkin_type") top.add(hidden) hidden.add_class("spt_checkin_type") grey_out_div = DivWdg() top.add(grey_out_div) grey_out_div.add_class("spt_publish_disable") grey_out_div.add_style("position: absolute") grey_out_div.add_style("left: 0px") grey_out_div.add_style("top: 10px") grey_out_div.add_style("opacity: 0.6") grey_out_div.add_color("background", "background") grey_out_div.add_style("height: 100%") grey_out_div.add_style("width: 100%") #grey_out_div.add_border() return top
def get_display(my): top = my.top top.add_class("spt_help_edit_top") top.add_color("background", "background") view = my.kwargs.get("view") from tactic.ui.container import ResizableTableWdg table = ResizableTableWdg() top.add(table) table.add_color("color", "color") table.add_style("width: 100%") table.add_style("height: 500px") table.add_row() left = table.add_cell() left.add_color("background", "background3") title_wdg = Table() title_wdg.add_row() left.add(title_wdg) title_wdg.add_gradient("background", "background", 0, -10) title_wdg.add_style("padding: 5px") title_wdg.add_style("margin-bottom: 5px") title_wdg.add_style("width: 100%") title_div = DivWdg("<b>Help Pages</b>") title_cell = title_wdg.add_cell(title_div) title_cell.add_style("width: 100%") from tactic.ui.widget import ActionButtonWdg insert_button = ActionButtonWdg(title="+", size="small") insert_button.add_style("margin-top: -3px") insert_button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var class_name = "tactic.ui.panel.EditWdg" var view = "edit" var title = "Add new help doc" var cbjs_insert = "spt.tab.reload_selected();" var kwargs = { 'view': view, 'search_type': 'config/widget_config', 'default': '{"category":"HelpWdg"}', 'ignore': 'search_type|login|config', 'mode': 'insert', //'cbjs_insert': cbjs_insert } spt.panel.load_popup(title, class_name, kwargs); ''' }) title_wdg.add_cell(insert_button) docs_wdg = my.get_doc_wdg() left.add(docs_wdg) left.add_style("width: 150px") left.add_style("min-width: 150px") left.add_style("min-height: 500px") left.add_style("vertical-align: top") left.add_border() right = table.add_cell() right.add_style("vertical-align: top") right.add_border() content = HelpEditContentWdg(view=view) right.add(content) return top
def get_display(my): top = my.top top.add_class("spt_db_config_top") top.add_style("width: 430px") top.add_style("min-height: 500") top.add_style("padding: 15px") top.add_style("margin-left: auto") top.add_style("margin-right: auto") top.add_color("background", "background", -10) top.add_border() title_wdg = DivWdg() top.add(title_wdg) title_wdg.add("System Configuration Setup") title_wdg.add_style("font-size: 20px") top.add("<hr/>") top.add("<i style='opacity: 0.5'>%s</i><br/>" % Config.get_config_path()) top.add("<br/>") checkin_keys = Config.get_section_values('checkin') checkin_keys = checkin_keys.keys() save_button = my.get_save_button(checkin_keys) top.add(save_button) vendor = Config.get_value("database", "vendor") title_wdg = DivWdg() top.add(title_wdg) title_wdg.add("<b>Database Setup</b>") title_wdg.add_style("margin-bottom: 10px") db_select = SelectWdg("database/vendor") db_select.set_option("labels", "SQLite|PostgreSQL|MySQL|Oracle|SQLServer") db_select.set_option("values", "Sqlite|PostgreSQL|MySQL|Oracle|SQLServer") db_select.set_value(vendor) db_select.add_behavior({ 'type': 'change', 'cbjs_action': ''' var key; if (bvr.src_el.value == 'Sqlite') { key = 'Sqlite'; } else if (bvr.src_el.value == 'MySQL') { key = 'MySQL'; } else { key = 'Other'; } var top = bvr.src_el.getParent(".spt_db_config_top"); var options_els = top.getElements(".spt_db_options"); for (var i = 0; i < options_els.length; i++) { var vendor = options_els[i].getAttribute("spt_vendor"); if (vendor == key) { spt.show(options_els[i]); } else { spt.hide(options_els[i]); } } ''' }) option_div = DivWdg() top.add(option_div) option_div.add("Vendor: ") option_div.add(db_select) option_div.add_style("margin: 20px") sqlite_wdg = my.get_sqlite_wdg() option_div.add(sqlite_wdg) mysql_wdg = my.get_mysql_wdg() option_div.add(mysql_wdg) otherdb_wdg = my.get_otherdb_wdg() option_div.add(otherdb_wdg) if vendor == 'Sqlite': sqlite_wdg.add_style("display", "") otherdb_wdg.add_style("display: none") mysql_wdg.add_style("display: none") if vendor == 'MySQL': mysql_wdg.add_style("display", "") otherdb_wdg.add_style("display: none") sqlite_wdg.add_style("display: none") else: otherdb_wdg.add_style("display", "") mysql_wdg.add_style("display: none") sqlite_wdg.add_style("display: none") test_button = ActionButtonWdg(title=" Test ", tip="Test connecting to database") option_div.add(test_button) test_button.add_style("margin-left: auto") test_button.add_style("margin-right: auto") test_button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_db_config_top"); var values = spt.api.Utility.get_input_values(top, null, false); var class_name = 'tactic.ui.startup.DbConfigCbk'; var server = TacticServerStub.get(); var kwargs = {}; var ret_val = server.execute_cmd(class_name, kwargs, values); var info = ret_val.info; if (info.error) { spt.error(info.error); } else { spt.info("Connection to database successful"); } ''' }) # # Install # top.add("<hr/>") top.add("<br/>") title = "Installation" category = "install" options = ['default_project'] if 'tmp_dir' not in options: options.append('tmp_dir') top.add(my.configure_category(title, category, options)) top.add("<hr/>") top.add("<br/>") top.add("<br/>") title = "Asset Management Setup" category = "checkin" options = checkin_keys[:] my._remove_item_from_list(options, 'win32_server_handoff_dir') my._remove_item_from_list(options, 'linux_server_handoff_dir') if os.name == "nt": options.append('win32_server_handoff_dir') else: options.append('linux_server_handoff_dir') top.add(my.configure_category(title, category, options)) top.add("<hr/>") top.add("<br/>") title = "Mail Server" category = "services" options = [ 'mailserver', 'mail_user', 'mail_password', 'mail_port', 'mail_tls_enabled', 'mail_sender_disabled' ] top.add(my.configure_category(title, category, options)) top.add("<hr/>") title = "Services" category = "services" options = [ 'process_count', 'process_time_alive', 'thread_count', 'python_path' ] top.add(my.configure_category(title, category, options)) top.add("<hr/>") title = "Look and Feel" category = "look" options = ['palette'] top.add(my.configure_category(title, category, options)) #wizard_wdg = WizardWdg() #top.add(wizard_wdg) #wizard_wdg.add(DivWdg("cow"), "cow") #wizard_wdg.add(DivWdg("pig"), "pig") #wizard_wdg.add(DivWdg("dog"), "dog") return top
def get_display(my): top = my.top my.set_as_panel(top) top.add_class("spt_delete_top") top.add_color("background", "background") top.add_color("color", "color") top.add_border() top.add_style("width: 300px") top.add_border() search_key = my.kwargs.get("search_key") search_keys = my.kwargs.get("search_keys") if search_key: sobject = Search.get_by_search_key(search_key) sobjects = [sobject] search_keys = [search_key] elif search_keys: sobjects = Search.get_by_search_keys(search_keys) sobject = sobjects[0] if not sobjects: msg = "%s not found" % search_key return msg search_type = sobject.get_base_search_type() if search_type in ['sthpw/project', 'sthpw/search_object']: msg = 'You cannot delete these items with this tool' return msg my.search_keys = search_keys title = DivWdg() top.add(title) title.add_color("background", "background", -10) if my.search_keys: title.add("Delete %s Items" % len(my.search_keys)) else: title.add("Delete Item [%s]" % (sobject.get_code())) title.add_style("font-size: 14px") title.add_style("font-weight: bold") title.add_style("padding: 10px") content = DivWdg() top.add(content) content.add_style("padding: 10px") content.add( "The item to be deleted has a number of dependencies as described below:<br/>", 'heading') # find all the relationships related_types = SearchType.get_related_types(search_type, direction='children') items_div = DivWdg() content.add(items_div) items_div.add_style("padding: 10px") valid_related_ctr = 0 for related_type in related_types: if related_type == "*": print "WARNING: related_type is *" continue if related_type == search_type: continue if related_type in ['sthpw/search_object', 'sthpw/search_type']: continue item_div = my.get_item_div(sobjects, related_type) if item_div: items_div.add(item_div) valid_related_ctr += 1 if valid_related_ctr > 0: icon = IconWdg("WARNING", IconWdg.WARNING) icon.add_style("float: left") content.add(icon) content.add( "<div><b>WARNING: By selecting the related items above, you can delete them as well when deleting this sObject.</b></div>" ) content.add("<br/>" * 2) else: # changed the heading to say no dependencies content.add("The item to be deleted has no dependencies.<br/>", 'heading') content.add("There are %s items to be deleted" % len(my.search_keys)) content.add("<br/>" * 2) content.add("Do you wish to continue deleting?") content.add("<br/>" * 2) button_div = DivWdg() button_div.add_styles('width: 300px; height: 75px') button = ActionButtonWdg(title="Delete") button_div.add(button) content.add(button_div) button.add_style("float: left") button.add_behavior({ 'type': 'click_up', 'search_keys': my.search_keys, 'cbjs_action': ''' spt.app_busy.show("Deleting"); var top = bvr.src_el.getParent(".spt_delete_top"); var values = spt.api.Utility.get_input_values(top); var class_name = "tactic.ui.tools.DeleteCmd"; var kwargs = { 'search_keys': bvr.search_keys, 'values': values }; var del_trigger = function() { // for fast table var tmps = spt.split_search_key(bvr.search_keys[0]) var tmps2 = tmps[0].split('?'); var del_st_event = "delete|" + tmps2[0]; var bvr_fire = {}; var input = {'search_keys': bvr.search_keys}; bvr_fire.options = input; spt.named_events.fire_event(del_st_event, bvr_fire); } var server = TacticServerStub.get(); try { server.start({'title': 'Delete sObject', 'description': 'Delete sObject [' + bvr.search_keys + ']'}); server.execute_cmd(class_name, kwargs); server.finish(); // run the post delete and destroy the popup var popup = bvr.src_el.getParent(".spt_popup"); if (popup.spt_on_post_delete) { popup.spt_on_post_delete(); } del_trigger(); spt.popup.destroy(popup); } catch(e) { spt.alert(spt.exception.handler(e)); } spt.app_busy.hide(); ''' }) button = ActionButtonWdg(title="Cancel") button.add_style("float: left") button_div.add(button) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_popup"); top.destroy(); ''' }) content.add("<br clear='all'/>") return top
def get_error_wdg(my): div = DivWdg() error_div = DivWdg() error_div.add("Error %s - Permission Denied" % my.status) div.add(error_div) error_div.add_style("font-size: 16px") error_div.add_style("font-weight: bold") error_div.add_style("width: 97%") error_div.add_gradient("background", "background") error_div.add_border() error_div.add_style("margin-left: 5px") error_div.add_style("margin-top: -10px") div.add("<br/>") span = DivWdg() #span.add_color("color", "color") span.add_style("color", "#FFF") if my.status == 403: span.add( "<b>You have tried to access a url that is not permitted.</b>") else: span.add(HtmlElement.b(my.message)) span.add(HtmlElement.br(2)) web = WebContainer.get_web() root = web.get_site_root() span.add("Go back to the Main page for a list of valid projects") div.add(span) div.add(HtmlElement.br()) table = Table() div.add(table) table.add_row() table.add_style("margin-left: auto") table.add_style("margin-right: auto") from tactic.ui.widget import ActionButtonWdg button = ActionButtonWdg(title="Go to Main", tip='Click to go to main page') table.add_cell(button) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' document.location = '/projects'; ''' }) button.add_style("margin-left: auto") button.add_style("margin-right: auto") button = ActionButtonWdg(title="Sign Out", tip='Click to Sign Out') table.add_cell(button) button.add_behavior({ 'type': 'click_up', 'login': web.get_user_name(), 'cbjs_action': ''' var server = TacticServerStub.get(); server.execute_cmd("SignOutCmd", {login: bvr.login} ); window.location.href='%s'; ''' % root }) button.add_style("margin-left: auto") button.add_style("margin-right: auto") return div
def get_display(my): top = my.top top.add_class("spt_db_config_top") top.add_style("width: 430px") top.add_style("min-height: 500") top.add_style("padding: 15px") top.add_style("margin-left: auto") top.add_style("margin-right: auto") top.add_color("background", "background", -10) top.add_border() title_wdg = DivWdg() top.add(title_wdg) title_wdg.add("System Configuration Setup") title_wdg.add_style("font-size: 20px") top.add("<hr/>") top.add("<i style='opacity: 0.5'>%s</i><br/>" % Config.get_config_path()) top.add("<br/>") checkin_keys=Config.get_section_values('checkin') checkin_keys=checkin_keys.keys() save_button = my.get_save_button(checkin_keys) top.add(save_button) vendor = Config.get_value("database", "vendor") title_wdg = DivWdg() top.add(title_wdg) title_wdg.add("<b>Database Setup</b>") title_wdg.add_style("margin-bottom: 10px") db_select = SelectWdg("database/vendor") db_select.set_option("labels", "SQLite|PostgreSQL|MySQL|Oracle|SQLServer") db_select.set_option("values", "Sqlite|PostgreSQL|MySQL|Oracle|SQLServer") db_select.set_value(vendor) db_select.add_behavior( { 'type': 'change', 'cbjs_action': ''' var key; if (bvr.src_el.value == 'Sqlite') { key = 'Sqlite'; } else { key = 'Other'; } var top = bvr.src_el.getParent(".spt_db_config_top"); var options_els = top.getElements(".spt_db_options"); for (var i = 0; i < options_els.length; i++) { var vendor = options_els[i].getAttribute("spt_vendor"); if (vendor == key) { spt.show(options_els[i]); } else { spt.hide(options_els[i]); } } ''' } ) option_div = DivWdg() top.add(option_div) option_div.add("Vendor: ") option_div.add(db_select) option_div.add_style("margin: 20px") sqlite_wdg = my.get_sqlite_wdg() option_div.add(sqlite_wdg) otherdb_wdg = my.get_otherdb_wdg() option_div.add(otherdb_wdg) if vendor == 'Sqlite': otherdb_wdg.add_style("display: none") sqlite_wdg.add_style("display", "") else: otherdb_wdg.add_style("display", "") sqlite_wdg.add_style("display: none") test_button = ActionButtonWdg(title="<< Test >>", tip="Test connecting to database") option_div.add(test_button) test_button.add_style("margin-left: auto") test_button.add_style("margin-right: auto") test_button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_db_config_top"); var values = spt.api.Utility.get_input_values(top, null, false); var class_name = 'tactic.ui.startup.DbConfigCbk'; var server = TacticServerStub.get(); var kwargs = {}; var ret_val = server.execute_cmd(class_name, kwargs, values); var info = ret_val.info; if (info.error) { spt.error(info.error); } else { spt.info("Connection to database successful"); } ''' } ) # # Install # top.add("<hr/>") top.add("<br/>") title = "Installation" category = "install" options = ['default_project'] if 'tmp_dir' not in options: options.append('tmp_dir') top.add( my.configure_category(title, category, options) ) top.add("<hr/>") top.add("<br/>") top.add("<br/>") title = "Asset Management Setup" category = "checkin" options=checkin_keys[:] my._remove_item_from_list(options,'win32_server_handoff_dir') my._remove_item_from_list(options,'linux_server_handoff_dir') if os.name == "nt": options.append('win32_server_handoff_dir') else: options.append('linux_server_handoff_dir') top.add( my.configure_category(title, category, options) ) top.add("<hr/>") top.add("<br/>") title = "Mail Server " category = "services" options = ['mailserver', 'mail_user', 'mail_password', 'mail_port', 'mail_tls_enabled', 'mail_sender_disabled'] top.add( my.configure_category(title, category, options) ) top.add("<hr/>") title = "Services" category = "services" options = ['process_count', 'process_time_alive', 'thread_count', 'python_path'] top.add( my.configure_category(title, category, options) ) top.add("<hr/>") title = "Look and Feel" category = "look" options = ['palette'] top.add( my.configure_category(title, category, options) ) #wizard_wdg = WizardWdg() #top.add(wizard_wdg) #wizard_wdg.add(DivWdg("cow"), "cow") #wizard_wdg.add(DivWdg("pig"), "pig") #wizard_wdg.add(DivWdg("dog"), "dog") return top
def get_action_wdg(my, name): '''get the action widget for ui option of note entry''' note_wdg = DivWdg() note_wdg.add_style("padding-top: 3px") # note options option = DivWdg(css='spt_uber_note_option') cb = CheckboxWdg('is_private') #cb.set_default_checked() checkbox_name = 'note_master_private_cb' master_cb = CheckboxWdg(checkbox_name) if master_cb.is_checked(): cb.set_default_checked() option.add_style('margin-right', '5px') option.add_style('float', 'right') option.add(cb) option.add('private') #commit = TextBtnWdg(label='save', size='small') commit = ActionButtonWdg(title='save', tip="Save Changes") commit.add_style('margin-top: -5px') commit.add_style('margin-bottom: 5px') commit.add_style('float: right') commit.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var td = bvr.src_el.getParent(".spt_table_td"); var text = td.getElement(".spt_note_text"); text.blur(); spt.dg_table.update_row(evt, bvr); td.setStyle('background-color',''); ''', 'cell_only': True }) #commit.set_scale("0.75") # do some gynastics to handle a refresh. if my.parent_wdg: info = my.parent_wdg.get_aux_info() sobject_dict = info.get('sobjects') sobject = sobject_dict.get(my.get_name()) parent = info.get('parent') else: sobject = None parent = None if not sobject: if my.parent_key: parent = SearchKey.get_by_search_key(my.parent_key) # get the latest note #search_key = my.kwargs.get("search_key") #if search_key: # sobject = SearchKey.get_by_search_key(search_key) search = Search('sthpw/note') search.add_parent_filter(parent) search.add_filter('context', name) # Make the assumption that the last one entered is by timestamp search.add_order_by('timestamp desc') sobject = search.get_sobject() # Show a history of notes if sobject: history = ActionButtonWdg(title='history', tip="Show note history") #history = TextBtnWdg(label='history', size='small') #history.get_top_el().add_style("margin-left: 4px") #history.get_top_el().add_style('float: left') history.add_style("float: left") history.add_style("margin-top: -5px") history.add_style("margin-bottom: 5px") note_wdg.add(history) my.parent_key = SearchKey.get_by_sobject(parent) context = name filter = '[{"prefix":"main_body","main_body_enabled":"on","main_body_column":"context","main_body_relation":"is","main_body_value":"%s"}]' % context history.add_behavior({ 'type': 'click_up', 'cbjs_action': "spt.popup.get_widget(evt, bvr)", 'options': { 'class_name': 'tactic.ui.panel.ViewPanelWdg', 'title': 'Notes History', 'popup_id': 'Notes_History_%s' % context }, 'args': { 'search_type': 'sthpw/note', 'view': 'summary', 'parent_key': my.parent_key, 'filter': filter, } }) note_wdg.add(commit) note_wdg.add(option) note_wdg.add("<br clear='all'/>") from pyasm.biz import PrefSetting quick_text = PrefSetting.get_value_by_key('quick_text') if quick_text: quick_sel = SelectWdg('quick_text', label='quick: ') quick_sel.set_option('values', quick_text) quick_sel.add_empty_option('-- text --', '') quick_sel.add_behavior({ 'type': 'change', 'cbjs_action': '''var val = bvr.src_el.value; var text=bvr.src_el.getParent('.spt_note_top').getElement('.spt_note_text') text.value = text.value + val; ''' }) note_wdg.add(SpanWdg(quick_sel, css='small')) note_wdg.add(HtmlElement.br(2)) # Show the last note note_wdg.add("<i>Last note</i> ") if sobject: timestamp = sobject.get_value("timestamp") timestamp = parser.parse(timestamp) timestamp = timestamp.strftime("%m/%d %H:%M") timestamp_div = SpanWdg() timestamp_div.add("(%s)" % timestamp) note_wdg.add(timestamp_div) timestamp_div.add_style("font-size: 11px") timestamp_div.add_style("font-style: italic") # add a private tag access = sobject.get_value("access") if access == 'private': private = SpanWdg() #private.add_style('float: right') private.add(" <i>-- private --</i>") note_wdg.add(private) hr = DivWdg("<hr/>") hr.add_style("height: 1px") hr.add_style("margin-top: -5px") note_wdg.add(hr) div = DivWdg() note_wdg.add(div) div.add_style("max-height", "50px") div.add_style("overflow", "auto") div.add_style("padding: 3px") if sobject: value = sobject.get_value('note') from pyasm.web import WikiUtil value = WikiUtil().convert(value) div.add(value) else: no_notes = DivWdg() div.add(no_notes) no_notes.add('<i> -- No Notes --</i>') no_notes.add_style("font-size: 11px") no_notes.add_style("opacity: 0.7") return note_wdg
def get_display(my): relative_dir = my.kwargs.get("relative_dir") my.relative_dir = relative_dir div = DivWdg() div.add_class("spt_ingest_top") div.add_style("width: 100%px") div.add_style("min-width: 500px") div.add_style("padding: 20px") div.add_color("background", "background") title_div = DivWdg() div.add(title_div) title_div.add("Ingest Files") title_div.add_style("font-size: 14px") title_div.add_style("font-weight: bold") title_div.add_style("padding: 10px") title_div.add_color("background", "background3") title_div.add_border() my.search_type = my.kwargs.get("search_type") if not my.search_type: div.add("No search type specfied") return div if relative_dir: folder_div = DivWdg() div.add(folder_div) folder_div.add("Folder: %s" % relative_dir) folder_div.add_style("opacity: 0.5") folder_div.add_style("font-style: italic") folder_div.add_style("margin-bottom: 10px") title_div.add_style("margin: -20px -21px 5px -21px") else: title_div.add_style("margin: -20px -21px 15px -21px") div.add("Add files or drag/drop files to be uploaded and ingested:") div.add("<br/>"*2) data_div = my.get_data_wdg() data_div.add_style("float: left") data_div.add_style("float: left") div.add(data_div) # create the help button help_button_wdg = DivWdg() div.add(help_button_wdg) help_button_wdg.add_style("margin-top: -3px") help_button_wdg.add_style("float: right") help_button = ActionButtonWdg(title="?", tip="Ingestion Widget Help", size='s') help_button_wdg.add(help_button) help_button.add_behavior( { 'type': 'click_up', 'cbjs_action': '''spt.help.load_alias("ingestion_widget")''' } ) from tactic.ui.input import Html5UploadWdg upload = Html5UploadWdg(multiple=True) div.add(upload) button = ActionButtonWdg(title="Add") button.add_style("float: right") button.add_style("margin-top: -3px") div.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingest_top"); var files_el = top.getElement(".spt_upload_files"); var onchange = function (evt) { var files = spt.html5upload.get_files(); for (var i = 0; i < files.length; i++) { spt.drag.show_file(files[i], files_el, 0, true); } } spt.html5upload.set_form( top ); spt.html5upload.select_file( onchange ); ''' } ) button = ActionButtonWdg(title="Clear") button.add_style("float: right") button.add_style("margin-top: -3px") div.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingest_top"); var file_els = top.getElements(".spt_upload_file"); for ( var i = 0; i < file_els.length; i++) { spt.behavior.destroy( file_els[i] ); }; ''' } ) div.add("<br clear='all'/>") files_div = DivWdg() files_div.add_style("position: relative") files_div.add_class("spt_upload_files") div.add(files_div) files_div.add_style("max-height: 300px") files_div.add_style("height: 300px") files_div.add_style("overflow-y: auto") files_div.add_border() files_div.add_style("padding: 3px") files_div.add_color("background", "background3") #files_div.add_style("display: none") bgcolor = div.get_color("background3") bgcolor2 = div.get_color("background3", -3) files_div.add_behavior( { 'type': 'mouseenter', 'bgcolor': bgcolor2, 'cbjs_action': ''' bvr.src_el.setStyle("background", bvr.bgcolor) ''' } ) files_div.add_behavior( { 'type': 'mouseout', 'bgcolor': bgcolor, 'cbjs_action': ''' bvr.src_el.setStyle("background", bvr.bgcolor) ''' } ) background = DivWdg() background.add_class("spt_files_background") files_div.add(background) background.add_style("font-size: 4.0em") background.add_style("font-weight: bold") background.add_style("opacity: 0.1") background.add_style("position: absolute") background.add_style("left: 50%") background.add_style("top: 100px") background.add_border() inner_background = DivWdg("Drag Files Here") background.add(inner_background) inner_background.set_style("position: absolute") inner_background.set_style("margin-left: -50%") # Test drag and drop files files_div.add_attr("ondragenter", "return false") files_div.add_attr("ondragover", "return false") files_div.add_attr("ondrop", "spt.drag.noop(event, this)") files_div.add_behavior( { 'type': 'load', 'cbjs_action': ''' spt.drag = {} var background; spt.drag.show_file = function(file, top, delay, icon) { if (!background) { background = top.getElement(".spt_files_background"); background.setStyle("display", "none"); } var template = top.getElement(".spt_upload_file_template"); var clone = spt.behavior.clone(template); clone.removeClass("spt_upload_file_template"); clone.addClass("spt_upload_file"); clone.setStyle("display", ""); if (typeof(delay) == 'undefined') { delay = 0; } // remember the file handle clone.file = file; var name = file.name; var size = parseInt(file.size / 1024 * 10) / 10; var thumb_el = clone.getElement(".spt_thumb"); var date_label_el = clone.getElement(".spt_date_label"); var date_el = clone.getElement(".spt_date"); //var loadingImage = loadImage( setTimeout( function() { if (icon) { var loadingImage = loadImage( file, function (img) { thumb_el.appendChild(img); }, {maxWidth: 80, maxHeight: 60, canvas: true, contain: true} ); } else { var img = $(document.createElement("div")); img.setStyle("width", "60"); img.setStyle("height", "40"); //img.innerHTML = "MP4"; img.setStyle("border", "solid 1px black") thumb_el.appendChild(img); } loadImage.parseMetaData( file, function(data) { if (data.exif) { var date = data.exif.get('DateTimeOriginal'); if (date) { date_label_el.innerHTML = date; if (date_el) { date_el.value = date; } } } } ); }, delay ); /* var reader = new FileReader(); reader.thumb_el = thumb_el; reader.onload = function(e) { this.thumb_el.innerHTML = [ '<img class="thumb" src="', e.target.result, '" title="', escape(name), '" width="60px"', '" padding="5px"', '"/>' ].join(''); } reader.readAsDataURL(file); */ clone.getElement(".spt_name").innerHTML = file.name; clone.getElement(".spt_size").innerHTML = size + " KB"; clone.inject(top); } spt.drag.noop = function(evt, el) { var top = $(el).getParent(".spt_ingest_top"); var files_el = top.getElement(".spt_upload_files"); evt.stopPropagation(); evt.preventDefault(); evt.dataTransfer.dropEffect = 'copy'; var files = evt.dataTransfer.files; var delay = 0; var skip = false; for (var i = 0; i < files.length; i++) { var size = files[i].size; if (size >= 10*1024*1024) { spt.drag.show_file(files[i], files_el, 0, false); } else { spt.drag.show_file(files[i], files_el, delay, true); if (size < 100*1024) delay += 50; else if (size < 1024*1024) delay += 500; else if (size < 10*1024*1024) delay += 1000; } } } ''' } ) # create a template that will be filled in for each file files_div.add_relay_behavior( { 'type': 'mouseenter', 'color': files_div.get_color("background3", -5), 'bvr_match_class': 'spt_upload_file', 'cbjs_action': ''' bvr.src_el.setStyle("background", bvr.color); ''' } ) files_div.add_relay_behavior( { 'type': 'mouseleave', 'bvr_match_class': 'spt_upload_file', 'cbjs_action': ''' bvr.src_el.setStyle("background", ""); ''' } ) files_div.add_relay_behavior( { 'type': 'mouseup', 'bvr_match_class': 'spt_remove', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_upload_file"); spt.behavior.destroy_element(top); ''' } ) """ metadata_view = "test/wizard/metadata" files_div.add_relay_behavior( { 'type': 'mouseup', 'view': metadata_view, 'bvr_match_class': 'spt_upload_file', 'cbjs_action': ''' var class_name = 'tactic.ui.panel.CustomLayoutWdg'; var kwargs = { view: bvr.view } spt.app_busy.show("Loading Metadata"); spt.panel.load_popup("Metadata", class_name, kwargs); spt.app_busy.hide(); ''' } ) """ # template for each file item file_template = DivWdg() file_template.add_class("spt_upload_file_template") files_div.add(file_template) file_template.add_style("margin-bottom: 3px") file_template.add_style("padding: 3px") file_template.add_style("height: 40px") file_template.add_style("display: none") thumb_div = DivWdg() file_template.add(thumb_div) thumb_div.add_style("float: left") thumb_div.add_style("width: 60"); thumb_div.add_style("height: 40"); thumb_div.add_style("overflow: hidden"); thumb_div.add_style("margin: 3 10 3 0"); thumb_div.add_class("spt_thumb") info_div = DivWdg() file_template.add(info_div) info_div.add_style("float: left") name_div = DivWdg() name_div.add_class("spt_name") info_div.add(name_div) name_div.add("image001.jpg") name_div.add_style("width: 150px") """ dialog = DialogWdg(display="false", show_title=False) info_div.add(dialog) dialog.set_as_activator(info_div, offset={'x':0,'y':10}) dialog_data_div = DivWdg() dialog_data_div.add_color("background", "background") dialog_data_div.add_style("padding", "10px") dialog.add(dialog_data_div) dialog_data_div.add("Category: ") text = TextInputWdg(name="category") dialog_data_div.add(text) text.add_class("spt_category") text.add_style("padding: 1px") """ date_div = DivWdg() date_div.add_class("spt_date_label") info_div.add(date_div) date_div.add("") date_div.add_style("opacity: 0.5") date_div.add_style("font-size: 0.8em") date_div.add_style("font-style: italic") date_div.add_style("margin-top: 3px") hidden_date_div = HiddenWdg("date") hidden_date_div.add_class("spt_date") info_div.add(date_div) size_div = DivWdg() size_div.add_class("spt_size") file_template.add(size_div) size_div.add("433Mb") size_div.add_style("float: left") size_div.add_style("width: 150px") size_div.add_style("text-align: right") remove_div = DivWdg() remove_div.add_class("spt_remove") file_template.add(remove_div) icon = IconButtonWdg(title="Remove", icon=IconWdg.DELETE) icon.add_style("float: right") remove_div.add(icon) #remove_div.add_style("text-align: right") div.add("<br/>") info = DivWdg() div.add(info) info.add_class("spt_upload_info") progress_div = DivWdg() progress_div.add_class("spt_upload_progress_top") div.add(progress_div) progress_div.add_style("width: 100%") progress_div.add_style("height: 15px") progress_div.add_style("margin-bottom: 10px") progress_div.add_border() #progress_div.add_style("display: none") progress = DivWdg() progress_div.add(progress) progress.add_class("spt_upload_progress") progress.add_style("width: 0px") progress.add_style("height: 100%") progress.add_gradient("background", "background3", -10) progress.add_style("text-align: right") progress.add_style("overflow: hidden") progress.add_style("padding-right: 3px") from tactic.ui.app import MessageWdg progress.add_behavior( { 'type': 'load', 'cbjs_action': MessageWdg.get_onload_js() } ) # NOTE: files variable is passed in automatically upload_init = ''' var server = TacticServerStub.get(); server.start( {description: "Upload and check-in of ["+files.length+"] files"} ); var info_el = top.getElement(".spt_upload_info"); info_el.innerHTML = "Uploading ..."; ''' upload_progress = ''' var top = bvr.src_el.getParent(".spt_ingest_top"); progress_el = top.getElement(".spt_upload_progress"); var percent = Math.round(evt.loaded * 100 / evt.total); progress_el.setStyle("width", percent + "%"); progress_el.innerHTML = String(percent) + "%"; ''' on_complete = ''' var top = bvr.src_el.getParent(".spt_ingest_top"); var progress_el = top.getElement(".spt_upload_progress"); progress_el.innerHTML = "100%"; progress_el.setStyle("width", "100%"); var info_el = top.getElement(".spt_upload_info"); var search_type = bvr.kwargs.search_type; var relative_dir = bvr.kwargs.relative_dir; var filenames = []; for (var i = 0; i != files.length;i++) { var name = files[i].name; filenames.push(name); } var key = spt.message.generate_key(); var values = spt.api.get_input_values(top); //var category = values.category[0]; var keywords = values.keywords[0]; var extra_data = values.extra_data[0]; var parent_key = values.parent_key[0]; var convert_el = top.getElement(".spt_image_convert") var convert = spt.api.get_input_values(convert_el); var processes = values.process; if (processes) { process = processes[0]; if (!process) { process = null; } } else { process = null; } var kwargs = { search_type: search_type, relative_dir: relative_dir, filenames: filenames, key: key, parent_key: parent_key, //category: category, keywords: keywords, extra_data: extra_data, process: process, convert: convert, } on_complete = function() { spt.info("Ingest complete"); server.finish(); var file_els = top.getElements(".spt_upload_file"); for ( var i = 0; i < file_els.length; i++) { spt.behavior.destroy( file_els[i] ); }; var background = top.getElement(".spt_files_background"); background.setStyle("display", ""); spt.message.stop_interval(key); }; var class_name = bvr.action_handler; server.execute_cmd(class_name, kwargs, null, {on_complete:on_complete}); on_progress = function(message) { msg = JSON.parse(message.message); var percent = msg.progress; var description = msg.description; info_el.innerHTML = description; progress_el.setStyle("width", percent+"%"); progress_el.innerHTML = percent + "%"; } spt.message.set_interval(key, on_progress, 2000); ''' upload_div = DivWdg() div.add(upload_div) #button = UploadButtonWdg(**kwargs) button = ActionButtonWdg(title="Ingest") upload_div.add(button) button.add_style("float: right") upload_div.add_style("margin-bottom: 15px") upload_div.add("<br clear='all'/>") action_handler = my.kwargs.get("action_handler") if not action_handler: action_handler = 'tactic.ui.tools.IngestUploadCmd'; button.add_behavior( { 'type': 'click_up', 'action_handler': action_handler, 'kwargs': { 'search_type': my.search_type, 'relative_dir': relative_dir }, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingest_top"); var file_els = top.getElements(".spt_upload_file"); // get the server that will be used in the callbacks var server = TacticServerStub.get(); // retrieved the stored file handles var files = []; for (var i = 0; i < file_els.length; i++) { files.push( file_els[i].file ); } if (files.length == 0) { alert("No files selected"); return; } // defined the callbacks var upload_start = function(evt) { } var upload_progress = function(evt) { %s; } var upload_complete = function(evt) { %s; spt.app_busy.hide(); } var upload_file_kwargs = { files: files, upload_start: upload_start, upload_complete: upload_complete, upload_progress: upload_progress }; if (bvr.ticket) upload_file_kwargs['ticket'] = bvr.ticket; %s; spt.html5upload.set_form( top ); spt.html5upload.upload_file(upload_file_kwargs); ''' % (upload_progress, on_complete, upload_init) } ) return div
def get_chat_wdg(self, key, interval=False): div = DivWdg() div.add_class("spt_chat_session_top") div.add_color("background", "background") title_wdg = DivWdg() div.add(title_wdg) title_wdg.add_color("background", "background3") title_wdg.add_style("padding: 5px") title_wdg.add_style("font-weight: bold") title_wdg.add_border() icon = IconButtonWdg(title="Remove Chat", icon=IconWdg.DELETE) icon.add_style("float: right") icon.add_style("margin-top: -5px") title_wdg.add(icon) icon.add_behavior( { 'type': 'click_up', 'key': key, 'cbjs_action': ''' var server = TacticServerStub.get(); var top = bvr.src_el.getParent(".spt_chat_session_top"); spt.behavior.destroy_element(top); ''' } ) current_user = Environment.get_user_name() logins = Search.eval("@SOBJECT(sthpw/subscription['message_code','%s'].sthpw/login)" % key) for login in logins: if login.get_value("login") == current_user: continue thumb = ThumbWdg() thumb.set_icon_size(45) thumb.set_sobject(login) thumb.add_style("float: left") thumb.add_style("margin: -5px 10px 0px -5px") title_wdg.add(thumb) title_wdg.add(login.get_value("display_name")) title_wdg.add("<br clear='all'/>") history_div = DivWdg() div.add(history_div) history_div.add_class("spt_chat_history") history_div.add_style("width: auto") history_div.add_style("height: auto") history_div.add_style("max-height: 400px") history_div.add_style("padding: 5px") history_div.add_class("spt_resizable") history_div.add_border() history_div.add_style("overflow-y: auto") #history_div.add_style("font-size: 0.9em") search = Search("sthpw/message_log") search.add_filter("message_code", key) search.add_order_by("timestamp") message_logs = search.get_sobjects() last_login = None; last_date = None; for message_log in message_logs: login = message_log.get("login") message = message_log.get("message") timestamp = message_log.get_datetime_value("timestamp") #timestamp = timestamp.strftime("%b %d, %Y - %H:%M") timestamp_str = timestamp.strftime("%H:%M") date_str = timestamp.strftime("%b %d, %Y") if login != last_login: table = Table() history_div.add(table) table.add_row() table.add_style("width: 100%") table.add_style("margin-top: 15px") login_sobj = Search.get_by_code("sthpw/login", login) thumb_div = DivWdg() td = table.add_cell() td.add_style("vertical-align: top") td.add_style("width: 75px") thumb_div = DivWdg() td.add(thumb_div) thumb_div.add_style("overflow: hidden") thumb = ThumbWdg() thumb_div.add(thumb) thumb.set_sobject(login_sobj) thumb.set_icon_size(60) display_name = login_sobj.get("display_name") td = table.add_cell() td.add_style("padding-top: 3px") name_div = DivWdg() td.add(name_div) name_div.add_style("color", "#214e75") name_div.add_style("font-size", "1.3em") name_div.add(display_name) msg = ""; msg += "<table style='margin-top: 5px; font-size: 1.0em; width: 100%'>"; if date_str != last_date: msg += "<tr><td colspan='2' style='text-align: right'><br/><b style='font-size: 1.0em'>"+date_str+"</b></td></tr>"; last_login = None msg += "<tr><td>" msg += message.replace("\n",'<br/>') msg += "</td><td style='vertical-align: top; text-align: right; margin-bottom: 5px; width: 75px; vertical-align: top; opacity: 0.7;'>"; msg += timestamp_str; msg += "</td></tr></table>"; td.add(msg) last_login = login last_date = date_str history_div.add_behavior( { 'type': 'load', 'cbjs_action': ''' bvr.src_el.scrollTop = bvr.src_el.scrollHeight; ''' } ) if message_logs: last_message = message_logs[-1].get("message") last_login = message_logs[-1].get("login") else: last_message = "" last_login = "" div.add_attr("spt_last_message", last_message) div.add_attr("spt_last_login", last_login) if interval: div.add_behavior( { 'type': 'load', 'key': key, 'cbjs_action': r''' var text_el = bvr.src_el.getElement(".spt_chat_text"); var history_el = bvr.src_el.getElement(".spt_chat_history"); var callback = function(message) { //history_el.setStyle("background", "red"); var login = message.login; var timestamp = message.timestamp; if (timestamp) { var parts = timestamp.split(" "); parts = parts[1].split("."); timestamp = parts[0]; } else { timestamp = ""; } var tmp = message.message || ""; var last_message = bvr.src_el.getAttribute("spt_last_message"); var last_login = bvr.src_el.getAttribute("spt_last_login"); if (tmp == last_message && login == last_login) { return; } bvr.src_el.setAttribute("spt_last_message", tmp); bvr.src_el.setAttribute("spt_last_login", login); var msg = ""; msg += "<table style='margin-top: 5px; font-size: 1.0em; width: 100%'><tr><td>"; if (login != last_login) { msg += "<b>"+login+"</b><br/>"; } msg += tmp.replace(/\n/g,'<br/>'); msg += "</td><td style='text-align: right; margin-bottom: 5px; width: 75px; vertical-align: top'>"; msg += timestamp; msg += "</td></tr></table>"; if (msg == history_el.last_msg) { return; } history_el.innerHTML = history_el.innerHTML + msg; // remember last message history_el.last_msg = msg; history_el.scrollTop = history_el.scrollHeight; } spt.message.set_interval(bvr.key, callback, 3000, bvr.src_el); ''' } ) text = TextAreaWdg("chat") div.add(text) text.add_class("spt_chat_text") text.add_style("width: 100%") text.add_style("padding: 5px") #text.add_style("margin-top: -1px") text.add_style("margin-top: 5px") text.add_behavior( { 'type': 'load', 'cbjs_action': ''' bvr.src_el.addEvent("keydown", function(e) { var keys = ['tab','keys(control+enter)', 'enter']; var key = e.key; var input = bvr.src_el if (keys.indexOf(key) > -1) e.stop(); if (key == 'tab') { } else if (key == 'enter') { if (e.control == false) { pass; } else { // TODO: check if it's multi-line first //... use ctrl-ENTER for new-line, regular ENTER (RETURN) accepts value //var tvals = parse_selected_text(input); //input.value = tvals[0] + "\\n" + tvals[1]; //spt.set_cursor_position( input, tvals[0].length + 1 ); } } } ) ''' } ) button = ActionButtonWdg(title="Send") div.add(button) button.add_style("float: right") button.add_style("margin: 5px") button.add_behavior( { 'type': 'click_up', 'key': key, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_chat_session_top"); var text_el = top.getElement(".spt_chat_text"); var message = text_el.value; if (!message) { return; } var history_el = top.getElement(".spt_chat_history"); var category = "chat"; var server = TacticServerStub.get(); var key = bvr.key; var last_message = server.log_message(key, message, {category:category, status:"in_progress"}); text_el.value = ""; ''' } ) div.add("<br clear='all'/>") return div
def get_display(self): top = self.top top.add_color("background", "background") top.add_color("color", "color") top.add_style("width", "400px") top.add_class('spt_delete_stype_top') top.add_border() project_code = Project.get_project_code() # Note search types should only really be deleted if they were just # created search_type = self.kwargs.get("search_type") if not search_type: node_name = self.kwargs.get("node_name") if node_name: #project_code = Project.get_project_code() search_type = "%s/%s" % (project_code, node_name) assert search_type built_in_stypes = ['task','note','work_hour','login','login_group','schema','project','login_in_group','snapshot','file','trigger','spt_trigger','widget_config','custom_script','notification','notification_log','file_access','cache','exception_log','milestone','pipeline','pref_list','pref_setting','project_type','repo','remote_repo','search_sobject','sobject_list','ticket','db_resource','wdg_settings','status_log','debug_log','transaction_log', 'sobject_log'] for tbl in built_in_stypes: if search_type == 'sthpw/%s'%tbl: top.add("sType [%s] is internal and cannot be deleted!" % search_type) top.add_style("font-size: 14px") top.add_style('padding: 20px') return top search_type_obj = SearchType.get(search_type) if not search_type: top.add("sType [%s] does not exist!" % search_type) top.add_style("font-size: 14px") top.add_style('padding: 20px') return top table = search_type_obj.get_table() db_val = search_type_obj.get_value('database') if db_val == '{project}': label = '' elif db_val == 'sthpw': label = 'built-in' else: label = 'project-specific' # warn if more than 1 sType point to the same table in the same project expr = "@GET(sthpw/search_type['table_name', '%s']['database', 'in', '{project}|%s']['namespace','%s'].search_type)" %(table, project_code, project_code) rtn = Search.eval(expr) warning_msg = '' if len(rtn) > 1: warning_msg = 'Warning: There is more than 1 sType [%s] pointing to the same table [%s]. Deleting will affect both sTypes.' %(', '.join(rtn), table) title_wdg = DivWdg() top.add(title_wdg) title_wdg.add(IconWdg(icon=IconWdg.WARNING)) title_wdg.add("Delete %s sType: %s" % (label,search_type)) title_wdg.add_color("background", "background", -10) title_wdg.add_style("font-weight: bold") title_wdg.add_style("font-size: 14px") content = DivWdg() top.add(content) content.add_style("padding: 10px") if warning_msg: content.add(DivWdg(warning_msg, css='warning')) content.add("<br/>") content.add("This sType uses the table \"%s\" to store items.<br/>" % table) content.add("<br/>") search = Search(search_type) count = search.get_count() content.add("Number of items in the table: %s<br/>" % count) content.add("<br/>") search.add_column("id") sobjects = search.get_sobjects() if sobjects: items_search_type = sobjects[0].get_search_type() search_ids = [x.get_id() for x in sobjects] notes_search = Search("sthpw/note") notes_search.add_filters("search_id", search_ids) notes_search.add_filter("search_type", items_search_type) note_count = notes_search.get_count() cb = CheckboxWdg('related_types') cb.set_attr('value', 'sthpw/note') content.add(cb) content.add(SpanWdg("Number of related notes: %s"% note_count, css='small') ) content.add(HtmlElement.br()) tasks_search = Search("sthpw/task") tasks_search.add_filters("search_id", search_ids) tasks_search.add_filter("search_type", items_search_type) task_count = tasks_search.get_count() cb = CheckboxWdg('related_types') cb.set_attr('value', 'sthpw/task') content.add(cb) content.add(SpanWdg("Number of related tasks: %s"% task_count, css='small') ) content.add(HtmlElement.br()) snapshots_search = Search("sthpw/snapshot") snapshots_search.add_filters("search_id", search_ids) snapshots_search.add_filter("search_type", items_search_type) snapshot_count = snapshots_search.get_count() cb = CheckboxWdg('related_types') cb.set_attr('value', 'sthpw/snapshot') content.add(cb) content.add(SpanWdg("Number of related snapshots: %s"% snapshot_count, css='small') ) content.add(HtmlElement.br()) pipelines_search = Search("sthpw/pipeline") pipelines_search.add_filter("search_type", search_type) pipeline_count = pipelines_search.get_count() cb = CheckboxWdg('related_types') cb.set_attr('value','sthpw/pipeline') content.add(cb) content.add(SpanWdg("Number of related pipelines: %s"% pipeline_count, css='small') ) content.add(HtmlElement.br(2)) content.add("<b>WARNING: Deleting the sType will delete all of these items.</b> ") content.add("<br/>"*2) content.add("Do you wish to continue deleting?") content.add("<br/>"*2) button_div = DivWdg() button_div.add_styles('width: 300px; height: 50px') button = ActionButtonWdg(title="Delete") button_div.add(button) content.add(button_div) button.add_style("float: left") button.add_behavior( { 'type': 'click_up', 'search_type': search_type, 'cbjs_action': ''' spt.app_busy.show("Deleting sType"); var class_name = "tactic.ui.tools.DeleteSearchTypeCmd"; var ui_top = bvr.src_el.getParent(".spt_delete_stype_top"); var values = spt.api.Utility.get_input_values(ui_top); var kwargs = { 'search_type': bvr.search_type, 'values': values }; var server = TacticServerStub.get(); try { server.start({'title': 'Delete sType', 'description': 'Delete sType [' + bvr.search_type + ']'}); server.execute_cmd(class_name, kwargs); var top = bvr.src_el.getParent(".spt_popup"); spt.pipeline.remove_node(top.stype_node); // force a schema save spt.named_events.fire_event('schema|save', bvr) top.destroy(); server.finish(); } catch(e) { spt.alert(spt.exception.handler(e)); } spt.app_busy.hide(); spt.notify.show_message("Successfully deleted sType ["+bvr.search_type+"]"); ''' } ) button = ActionButtonWdg(title="Cancel") button.add_style("float: left") button_div.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_popup"); top.destroy(); ''' } ) return top
def get_display(self): top = DivWdg() top.add_color("background", "background") top.add_color("color", "color") top.add_style("min-width: 600px") os_name = os.name top.set_unique_id() top.add_smart_style("spt_info_title", "background", self.top.get_color("background3")) top.add_smart_style("spt_info_title", "padding", "3px") top.add_smart_style("spt_info_title", "font-weight", "bold") # server title_div = DivWdg() top.add(title_div) title_div.add("Server") title_div.add_class("spt_info_title") os_div = DivWdg() top.add(os_div) os_info = platform.uname() try: os_login = os.getlogin() except Exception: os_login = os.environ.get("LOGNAME") table = Table() table.add_color("color", "color") table.add_style("margin: 10px") os_div.add(table) for i, title in enumerate( ['OS', 'Node Name', 'Release', 'Version', 'Machine']): table.add_row() td = table.add_cell("%s: " % title) td.add_style("width: 150px") table.add_cell(os_info[i]) table.add_row() table.add_cell("CPU Count: ") try: import multiprocessing table.add_cell(multiprocessing.cpu_count()) except (ImportError, NotImplementedError): table.add_cell("n/a") table.add_row() table.add_cell("Login: "******"Python") title_div.add_class("spt_info_title") table = Table() table.add_color("color", "color") table.add_style("margin: 10px") top.add(table) table.add_row() td = table.add_cell("Version: ") td.add_style("width: 150px") table.add_cell(sys.version) # client title_div = DivWdg() top.add(title_div) title_div.add("Client") title_div.add_class("spt_info_title") web = WebContainer.get_web() user_agent = web.get_env("HTTP_USER_AGENT") table = Table() table.add_color("color", "color") table.add_style("margin: 10px") top.add(table) table.add_row() td = table.add_cell("User Agent: ") td.add_style("width: 150px") table.add_cell(user_agent) table.add_row() td = table.add_cell("TACTIC User: "******"Performance Test") title_div.add_class("spt_info_title") performance_wdg = PerformanceWdg() top.add(performance_wdg) top.add('<br/>') # mail server title_div = DivWdg() top.add(title_div) title_div.add("Mail Server") title_div.add_class("spt_info_title") table = Table(css='email_server') table.add_color("color", "color") table.add_style("margin: 10px") top.add(table) table.add_row() td = table.add_cell("Server: ") td.add_style("width: 150px") mailserver = Config.get_value("services", "mailserver") has_mailserver = True if mailserver: table.add_cell(mailserver) else: table.add_cell("None configured") has_mailserver = False login = Login.get_by_login('admin') login_email = login.get_value('email') table.add_row() td = table.add_cell("From: ") td.add_style("width: 150px") text = TextWdg('email_from') text.set_attr('size', '40') text.set_value(login_email) text.add_class('email_from') table.add_cell(text) table.add_row() td = table.add_cell("To: ") td.add_style("width: 150px") text = TextWdg('email_to') text.set_attr('size', '40') text.add_class('email_to') text.set_value(login_email) table.add_cell(text) button = ActionButtonWdg(title='Email Send Test') table.add_row_cell('<br/>') table.add_row() table.add_cell(button) button.add_style("float: right") button.add_behavior({ 'type': 'click_up', 'has_mailserver': has_mailserver, 'cbjs_action': ''' if (!bvr.has_mailserver) { spt.alert('You have to fill in mailserver and possibly other mail related options in the TACTIC config file to send email.'); return; } var s = TacticServerStub.get(); try { spt.app_busy.show('Sending email'); var from_txt = bvr.src_el.getParent('.email_server').getElement('.email_from'); var to_txt = bvr.src_el.getParent('.email_server').getElement('.email_to'); var rtn = s.execute_cmd('pyasm.command.EmailTriggerTestCmd', {'sender_email': from_txt.value, 'recipient_emails': to_txt.value.split(','), 'msg': 'Simple Email Test by TACTIC'} ); if (rtn.status == 'OK') { spt.info("Email sent successfully to " + to_txt.value) } } catch(e) { spt.alert(spt.exception.handler(e)); } spt.app_busy.hide(); ''' }) top.add('<br/>') self.handle_directories(top) #table.add_row() #td = table.add_cell("TACTIC User: ") #table.add_cell( web.get_user_name() ) top.add('<br/>') top.add(DivWdg('Link Test', css='spt_info_title')) top.add('<br/>') top.add(LinkLoadTestWdg()) top.add('<br/>') self.handle_python_script_test(top) top.add('<br/>') self.handle_sidebar_clear(top) return top
def get_display(my): expr_filter = "sthpw/login['login','not in','admin|guest']['begin']['license_type','user']['license_type','is','NULL']['or']" current_users = Search.eval("@COUNT(%s)" %expr_filter) top = my.top top.add_class("spt_panel_user_top") top.add_style("min-width: 400px") tool_div = DivWdg() # tool_div.add_style('margin-bottom','8px') tool_div.add_style('display','inline-flex') tool_div.add_style('width','50%') tool_div.add_style('margin-bottom','-4px') button = ActionButtonWdg(title="Add", tip="Add New User") button.add_style('align-self: flex-end') tool_div.add(button) button.add_style("float: left") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var class_name = 'tactic.ui.panel.EditWdg'; var kwargs = { search_type: "sthpw/login", view: "edit", show_header: false, } var popup = spt.panel.load_popup("Create New User", class_name, kwargs); var top = bvr.src_el.getParent(".spt_panel_user_top"); popup.on_save_cbk = function() { spt.panel.refresh(top); } ''' } ) security = Environment.get_security() license = security.get_license() num_left = license.get_num_licenses_left() current_users = license.get_current_users() #max_users = license.get_max_users() div = DivWdg('Users') div.add_style('align-self: flex-end') div.add_styles("margin: 0 0 6px 20px") badge_span = SpanWdg(css='badge') badge_span.add_style('margin-left','6px') badge_span.add(current_users) div.add(badge_span) tool_div.add(div) tool_div2 = DivWdg() # tool_div.add_style('margin-bottom','8px') tool_div2.add_style('display','inline-flex') tool_div2.add_style('justify-content','flex-end') tool_div2.add_style('width','50%') top.add(tool_div) top.add(tool_div2) if num_left < 1000: div = DivWdg('Users Left') div.add_style('align-self: flex-end') div.add_styles("margin: 0 0 6px 20px") badge_span = SpanWdg(css='badge') badge_span.add_style('margin-left','6px') badge_span.add(num_left) div.add(badge_span) tool_div.add(div) top.add(tool_div) show_security = my.kwargs.get("show_security") if show_security not in ['false', False]: button = ActionButtonWdg(title="Security") button.add_style('align-self: flex-end') #button.add_styles("position: absolute; right: 10px;") tool_div2.add(button) #button.add_style("margin-top: -8px") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var class_name = 'tactic.ui.startup.SecurityWdg'; spt.tab.set_main_body_tab() spt.tab.add_new("Security", "Security", class_name) ''' } ) br = HtmlElement.br(clear=True) top.add(br) if not current_users: div = DivWdg() top.add(div) div.add_style("text-align: center") div.add_border() div.add_style("min-height: 150px") div.add_style("margin: 15px 30px 30px 30px") div.add_style("padding: 30px 20px 0px 20px") div.add_color("background", "background3") icon = IconWdg( "WARNING", IconWdg.WARNING ) div.add(icon) div.add("<b>No users have been added</b>") div.add("<br/><br/>") div.add("For more information, read the help docs: ") from tactic.ui.app import HelpButtonWdg help = HelpButtonWdg(alias=my.get_help_alias()) div.add(help) div.add("<br/>") div.add("Click on the 'Add' button above to start adding new users.") return top div = DivWdg() top.add(div) #div.add_style("max-height: 300px") #div.add_style("overflow-y: auto") expr = "@SEARCH(%s)" %expr_filter panel = ViewPanelWdg(search_type='sthpw/login',view='manage_user',show_insert='false',\ show_gear='false', show_select='false', height='700', expression=expr,\ simple_search_view='simple_manage_filter', show_column_manager='false',\ show_layout_switcher='false', show_expand='false') div.add(panel) div.add_style('margin-top', '4px') return top """
def get_display(self): self.check() if self.is_refresh: div = Widget() else: div = DivWdg() self.set_as_panel(div) div.add_style('padding', '6px') min_width = '400px' div.add_style('min-width', min_width) div.add_color('background', 'background') div.add_class('spt_add_task_panel') div.add_style("padding: 20px") from tactic.ui.app import HelpButtonWdg help_button = HelpButtonWdg(alias="creating-tasks") div.add(help_button) help_button.add_style("float: right") help_button.add_style("margin-top: -5px") if not self.search_key_list: msg_div = DivWdg() msg_table = Table() msg_div.add(msg_table) msg_table.add_row() msg_table.add_cell(IconWdg("No items selected", IconWdg.WARNING)) msg_table.add_cell( 'Please select at least 1 item to add tasks to.') msg_div.add_style('margin: 10px') msg_table.add_style("font-weight: bold") div.add(msg_div) return div msg_div = DivWdg() msg_div.add_style('margin-left: 4px') div.add(msg_div, 'info') msg_div.add('Total: %s item/s to add tasks to' % len(self.search_key_list)) div.add(HtmlElement.br()) hint = HintWdg('Tasks are added according to the assigned pipeline.') msg_div.add(" ") msg_div.add(hint) msg_div.add(HtmlElement.br()) option_div = DivWdg(css='spt_ui_options') #option_div.add_style('margin-left: 12px') sel = SelectWdg('pipeline_mode', label='Create tasks by: ') sel.set_option('values', ['simple process', 'context', 'standard']) sel.set_option('labels', ['process', 'context', 'all contexts in process']) sel.set_persistence() sel.add_behavior({ 'type': 'change', 'cbjs_action': 'spt.panel.refresh(bvr.src_el)' }) option_div.add(sel) value = sel.get_value() # default to simple process if not value: value = 'simple process' msg = '' if value not in ['simple process', 'context', 'standard']: value = 'simple process' if value == 'context': msg = 'In context mode, a single task will be created for each selected context.' elif value == 'simple process': msg = 'In process mode, a single task will be created for each selected process.' elif value == 'standard': msg = 'In this mode, a task will be created for all contexts of each selected process.' option_div.add(HintWdg(msg)) div.add(option_div) div.add(HtmlElement.br()) title = DivWdg('Assigned Pipelines') title.add_style('padding: 6px') title.add_color('background', 'background2') title.add_color('color', 'color', +120) div.add(title) content_div = DivWdg() content_div.add_style('min-height', '150px') div.add(content_div) content_div.add_border() filtered_search_key_list = [] for sk in self.search_key_list: id = SearchKey.extract_id(sk) if id == '-1': continue filtered_search_key_list.append(sk) sobjects = SearchKey.get_by_search_keys(filtered_search_key_list) skipped = [] pipeline_codes = [] for sobject in sobjects: if isinstance(sobject, Task): msg_div = DivWdg( 'WARNING: Creation of task for [Task] is not allowed.') msg_div.add_style('margin-left: 10px') div.add(msg_div, 'info') return div pipeline_code = sobject.get_value('pipeline_code', no_exception=True) if not pipeline_code: skipped.append(sobject) if pipeline_code not in pipeline_codes: pipeline_codes.append(pipeline_code) pipelines = Search.get_by_code('sthpw/pipeline', pipeline_codes) if pipelines == None: pipelines = [] #if not pipelines: # msg_div = DivWdg('WARNING: No Pipelines found for selected.') # msg_div.add_style('margin-left: 10px') # div.add(msg_div, 'info') # return div # expand the width according to num of pipelines content_div.add_style('min-width', len(pipelines) * 250) mode_cb = SelectWdg('pipeline_mode') mode_cb.set_persistence() mode = mode_cb.get_value() if 'context' == mode: mode = 'context' else: mode = 'process' show_subpipeline = True min_height = '150px' # create a temp default pipeline if not pipelines: pipeline = SearchType.create("sthpw/pipeline") pipeline.set_value("code", "__default__") pipeline.set_value( "pipeline", ''' <pipeline> <process name='publish'/> </pipeline> ''') # FIXME: HACK to initialize virtual pipeline pipeline.set_pipeline(pipeline.get_value("pipeline")) pipelines = [pipeline] for pipeline in pipelines: name = pipeline.get_value("name") if not name: name = pipeline.get_code() span = SpanWdg("Pipeline: %s" % name) span.add_style('font-weight: bold') v_div = FloatDivWdg(span) v_div.add_style('margin: 20px') v_div.add_style('min-height', min_height) v_div.add(HtmlElement.br(2)) content_div.add(v_div) processes = pipeline.get_processes(recurse=show_subpipeline, type=['manual', 'approval']) cb_name = '%s|task_process' % pipeline.get_code() master_cb = CheckboxWdg('master_control') master_cb.set_checked() master_cb.add_behavior({ 'type': 'click_up', 'propagate_evt': True, 'cbjs_action': ''' var inputs = spt.api.Utility.get_inputs(bvr.src_el.getParent('.spt_add_task_panel'),'%s'); for (var i = 0; i < inputs.length; i++) inputs[i].checked = bvr.src_el.checked; ''' % cb_name }) toggle_div = DivWdg() toggle_div.add(SpanWdg(master_cb, css='small')) label = HtmlElement.i('toggle all') label.add_style('color: #888') toggle_div.add_styles( 'border-bottom: 1px solid #888; width: 170px') toggle_div.add(label) v_div.add(toggle_div) process_names = [] for process in processes: process_labels = [] if process.is_from_sub_pipeline(): process_name = process.get_full_name() else: process_name = process.get_name() process_label = process.get_label() if not process_label: process_label = '' if mode == 'context': contexts = pipeline.get_output_contexts(process.get_name()) labels = contexts if process.is_from_sub_pipeline(): labels = [ '%s/%s' % (process.parent_pipeline_code, x) for x in contexts ] for x in labels: process_labels.append(process_label) # prepend process to contexts in this mode to ensure uniqueness contexts = ['%s:%s' % (process_name, x) for x in contexts] else: contexts = [process_name] labels = contexts process_labels.append(process_label) for idx, context in enumerate(contexts): cb = CheckboxWdg(cb_name) cb.set_checked() cb.set_option('value', context) v_div.add(SpanWdg(cb, css='small')) if mode == 'context': span = SpanWdg(process_name, css='med') #span.add_color('color','color') v_div.add(span) v_div.add(SpanWdg(labels[idx])) process_label = process_labels[idx] if process_label: v_div.add(SpanWdg("(%s)" % process_label, css='small')) v_div.add(HtmlElement.br()) content_div.add("<br clear='all'/>") skipped = [] if True: div.add("<br/>") btn = ActionButtonWdg(title='Add Tasks') btn.add_behavior({ 'type': 'click_up', 'post_event': 'search_table_%s' % self.table_id, 'cbjs_action': ''' spt.dg_table.add_task_selected(bvr); ''', 'search_key_list': self.search_key_list }) cb = CheckboxWdg('skip_duplicated', label='Skip Duplicates') cb.set_checked() option_div = DivWdg(cb) option_div.add_style('width', '130px') option_div.add_style('align: left') div.add(option_div) div.add(HtmlElement.br()) btn.add_style("float: right") div.add(btn) div.add(HtmlElement.br(clear="all")) if skipped: content_div.add(HtmlElement.br()) skip_div = DivWdg('Missing pipeline code (Skipped)') skip_div.add_style('text-decoration: underline') content_div.add(skip_div) content_div.add(HtmlElement.br()) item_div = DivWdg() item_div.add_style('margin-left: 10px') content_div.add(item_div) for skip in skipped: item_div.add(skip.get_code()) item_div.add(HtmlElement.br()) return div