def set_filter_data(search_type, view=None): '''set filter data based on some saved search values in wdg_settings''' # NOTE - This is MMS specific and is deprecated and will be deleted # DISABLING FOR Job and Request until job_detail stops stack tracing # This is due to mixing of searches between job and request in the # job detail. Cannot find the issue. # 1) FilterData is global: should be scoped by search type # 2) After introduction of scroll bars, it started stack tracing # It looks like the state is not being properly passed through # temp fix to avoid cross contamination of filter data for Planners UI if search_type in ['MMS/job','MMS/request'] or view == '_planner': return filter_data = FilterData.get() if not filter_data.get_data(): # use widget settings key = SearchWdg._get_key(search_type, view) data = WidgetSettings.get_value_by_key(key) if data: try: filter_data = FilterData(data) filter_data.set_to_cgi() except SetupException, e: print "This filter data is causing error:", data print e
def set_filter_data(search_type, view=None): '''set filter data based on some saved search values in wdg_settings''' # NOTE - This is MMS specific and is deprecated and will be deleted # DISABLING FOR Job and Request until job_detail stops stack tracing # This is due to mixing of searches between job and request in the # job detail. Cannot find the issue. # 1) FilterData is global: should be scoped by search type # 2) After introduction of scroll bars, it started stack tracing # It looks like the state is not being properly passed through # temp fix to avoid cross contamination of filter data for Planners UI if search_type in ['MMS/job', 'MMS/request'] or view == '_planner': return filter_data = FilterData.get() if not filter_data.get_data(): # use widget settings key = SearchWdg._get_key(search_type, view) data = WidgetSettings.get_value_by_key(key) if data: try: filter_data = FilterData(data) filter_data.set_to_cgi() except SetupException, e: print "This filter data is causing error:", data print e
def set_filter_data(search_type, view=None): '''set filter data based on some saved search values in wdg_settings''' filter_data = FilterData.get() if not filter_data.get_data(): # use widget settings key = SearchWdg._get_key(search_type, view) data = WidgetSettings.get_value_by_key(key) if data: try: filter_data = FilterData(data) filter_data.set_to_cgi() except SetupException, e: print "This filter data is causing error:", data print e
def get_config_xml(my): from pyasm.web import WidgetSettings config_xml = WidgetSettings.get_value_by_key("main_body_tab") config_xml = None if not config_xml: config_xml = '''<config><tab/></config>''' """ config_xml = '''<config><tab> <element name='Ingestion'> <display class='tactic.ui.widget.file_browser_wdg.FileBrowserWdg'> <search_type>sthpw/login_group</search_type> <view>table</view> </display> </element> </tab> </config>''' """ return config_xml
def get_config_xml(self): from pyasm.web import WidgetSettings config_xml = WidgetSettings.get_value_by_key("main_body_tab") config_xml = None if not config_xml: config_xml = '''<config><tab/></config>''' """ config_xml = '''<config><tab> <element name='Ingestion'> <display class='tactic.ui.widget.file_browser_wdg.FileBrowserWdg'> <search_type>sthpw/login_group</search_type> <view>table</view> </display> </element> </tab> </config>''' """ return config_xml
def alter_task_search(self, search, prefix='children', prefix_namespace='' ): from tactic.ui.filter import FilterData, BaseFilterWdg, GeneralFilterWdg filter_data = FilterData.get() parent_search_type = get_search_type() if not filter_data.get_data(): # use widget settings key = "last_search:%s" % parent_search_type data = WidgetSettings.get_value_by_key(key) if data: filter_data = FilterData(data) filter_data.set_to_cgi() filter_mode_prefix = 'filter_mode' if prefix_namespace: filter_mode_prefix = '%s_%s' %(prefix_namespace, filter_mode_prefix) filter_mode = 'and' filter_mode_value = filter_data.get_values_by_index(filter_mode_prefix, 0) if filter_mode_value: filter_mode = filter_mode_value.get('filter_mode') if prefix_namespace: prefix = '%s_%s' %(prefix_namespace, prefix) values_list = BaseFilterWdg.get_search_data_list(prefix, \ search_type=self.get_searchable_search_type()) if values_list: search.add_op('begin') GeneralFilterWdg.alter_sobject_search( search, values_list, prefix) if filter_mode != 'custom': search.add_op(filter_mode) return search
def alter_task_search(my, search, prefix='children', prefix_namespace='' ): from tactic.ui.filter import FilterData, BaseFilterWdg, GeneralFilterWdg filter_data = FilterData.get() parent_search_type = get_search_type() if not filter_data.get_data(): # use widget settings key = "last_search:%s" % parent_search_type data = WidgetSettings.get_value_by_key(key) if data: filter_data = FilterData(data) filter_data.set_to_cgi() filter_mode_prefix = 'filter_mode' if prefix_namespace: filter_mode_prefix = '%s_%s' %(prefix_namespace, filter_mode_prefix) filter_mode = 'and' filter_mode_value = filter_data.get_values_by_index(filter_mode_prefix, 0) if filter_mode_value: filter_mode = filter_mode_value.get('filter_mode') if prefix_namespace: prefix = '%s_%s' %(prefix_namespace, prefix) values_list = BaseFilterWdg.get_search_data_list(prefix, \ search_type=my.get_searchable_search_type()) if values_list: search.add_op('begin') GeneralFilterWdg.alter_sobject_search( search, values_list, prefix) if filter_mode != 'custom': search.add_op(filter_mode) return search
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 add_top_behaviors(my, top): super(ScmDirListWdg, my).add_top_behaviors(top) changelist = WidgetSettings.get_value_by_key("current_changelist") menu_item = MenuItem(type='title', label="Perforce Actions") my.menu.add(menu_item) menu_item = MenuItem(type='action', label='Add To Changelist [%s]' % changelist) my.menu.add(menu_item) menu_item.add_behavior( { 'type': 'click_up', 'changelist': changelist, 'cbjs_action': ''' var activator = spt.smenu.get_activator(bvr); var paths = spt.checkin.get_selected_paths(); if (paths.length == 0) { var path = activator.getAttribute("spt_path"); paths = [path] } var changelist = bvr.changelist; // TODO: optimize this to call on once by passing in the array // of paths for (var i = 0; i < paths.length; i++) { var path = paths[i]; spt.scm.run("add", [path, changelist]); } var top = activator.getParent(".spt_checkin_top"); spt.panel.refresh(top); ''' } ) menu_item = MenuItem(type='action', label='Make Editable') my.menu.add(menu_item) menu_item.add_behavior( { 'type': 'click_up', 'changelist': changelist, 'cbjs_action': ''' var activator = spt.smenu.get_activator(bvr); var paths = spt.checkin.get_selected_paths(); if (paths.length == 0) { var path = activator.getAttribute("spt_path"); paths = [path] } // TODO: optimize this to call on once by passing in the array // of paths for (var i = 0; i < paths.length; i++) { var path = paths[i]; spt.scm.run("edit", [path, bvr.changelist]); } var top = activator.getParent(".spt_checkin_top"); spt.panel.refresh(top); ''' } ) menu_item = MenuItem(type='action', label='Revert File') my.menu.add(menu_item) menu_item.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var activator = spt.smenu.get_activator(bvr); var path = activator.getAttribute("spt_path"); try { spt.scm.revert(path); var top = activator.getParent(".spt_checkin_top"); spt.panel.refresh(top); } catch (e) { spt.scm.handle_error(e); } ''' } ) menu_item = MenuItem(type='action', label='File Log') my.menu.add(menu_item) menu_item.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var activator = spt.smenu.get_activator(bvr); var path = activator.getAttribute("spt_path"); try { var file_logs = spt.scm.file_log(path); var class_name = 'tactic.ui.checkin.ScmCheckinHistoryWdg'; var kwargs = { 'file_logs': file_logs } spt.panel.load_popup("Check-in History", class_name, kwargs); } catch (e) { spt.scm.handle_error(e); } ''' } )
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(self): top = self.top top.add_class("spt_switcher_top") ''' This supports supports two menu definitions: menu - specifies a view for SideBarWdg which will be ingected as menu config_xml - specifies menu entries. For example: <display class="tactic.ui.widget.LayoutSwitcherWdg"> <!-- config_xml --> <config> <!-- Menu item 1 --> <element name="self_tasks_default" title="My Tasks" target=spt_my_tasks_table_top"> <display class="tactic.ui.panel.ViewPanelWdg"> <search_type>sthpw/task</search_type> <show_shelf>false</show_shelf> <view>my_tasks_default</view> </display> </element> <!-- Menu item 2 --> <element ... > <display ... > </display> </element> </config> </display> target - specifies target div to load views when using "menu" kwarg use_href - updates address bar hash (this is TODO) ''' menu = self.kwargs.get("menu") config_xml = self.kwargs.get("config_xml") target = self.kwargs.get("target") #default default_layout = self.kwargs.get("default_layout") # find the save state value, if state is to be saved save_state = self.kwargs.get("save_state") if save_state in [False, 'false']: save_state = None show_first = False else: show_first = True state_value = None if save_state: state_value = WidgetSettings.get_value_by_key(save_state) elif default_layout: state_value = default_layout title = self.kwargs.get("title") if not title and state_value: title = state_value if not title: title = "Switch Layout" mode = self.kwargs.get("mode") if mode == "button": color = self.kwargs.get("color") or "default" activator = DivWdg("<button class='btn btn-%s dropdown-toggle' style='width: 160px'><span class='spt_title'>%s</span> <span class='caret'></span></button>" % (color, title)) elif mode == "div": color = self.kwargs.get("color") or "" background = self.kwargs.get("background") or "transparent" activator = DivWdg("<button class='btn dropdown-toggle' style='width: 160px; background: %s; color: %s; font-weight: bold'><span class='spt_title'>%s</span> <span class='caret'></span></button>" % (background, color, title)) else: activator = IconButtonWdg( name="Layout Switcher", icon="BS_TH_LIST") top.add(activator) activator.add_class("spt_switcher_activator") activator.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var activator = bvr.src_el; var top = activator.getParent(".spt_switcher_top"); var menu = top.getElement(".spt_switcher_menu"); if (top.hasClass("spt_selected")) { top.removeClass("spt_selected"); menu.setStyle("display", "none"); } else { top.addClass("spt_selected"); menu.setStyle("display", ""); var pos = activator.getPosition(); var button_size = activator.getSize(); var menu_size = menu.getSize(); var offset = { x: button_size.x - menu_size.x, y: button_size.y } menu.position({position: 'upperleft', relativeTo: activator, offset: offset}); spt.body.add_focus_element(menu); var pointer = menu.getElement(".spt_switcher_popup_pointer"); pointer.setStyle("margin-left", menu_size.x - button_size.x); } ''' } ) outer_wdg = DivWdg() top.add(outer_wdg) # menu_wdg menu_wdg = DivWdg() outer_wdg.add(menu_wdg) menu_wdg.add_color("color", "color") menu_wdg.add_color("background", "background") menu_wdg.add_border() menu_wdg.add_class("spt_switcher_menu") menu_wdg.add_style("display: none") menu_wdg.add_style("margin-top", "20px") menu_wdg.add_style("position", "absolute") menu_wdg.add_style("z-index", "101") menu_wdg.add_behavior( { 'type': 'mouseleave', 'cbjs_action': ''' var menu = bvr.src_el; var top = menu.getParent(".spt_switcher_top"); top.removeClass("spt_selected"); menu.setStyle("display", "none") ''' } ) border_color = menu_wdg.get_color("border") # Pointer under activator pointer_wdg = DivWdg() menu_wdg.add(pointer_wdg) pointer_wdg.add(''' <div class="spt_switcher_first_arrow_div"> </div> <div class="spt_switcher_second_arrow_div"> </div> ''') pointer_wdg.add_class("spt_switcher_popup_pointer") style = HtmlElement.style(''' .spt_switcher_menu .spt_switcher_popup_pointer { z-index: 10; position: absolute; top: -15px; right: 15px; } .spt_switcher_menu .spt_switcher_first_arrow_div { border-color: rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) %s; top: -15px; z-index: 1; border-width: 0 15px 15px; height: 0; width: 0; border-style: dashed dashed solid; left: 15px; } .spt_switcher_menu .spt_switcher_second_arrow_div{ border-color: rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) #fff; z-index: 1; border-width: 0 15px 15px; height: 0; width: 0; border-style: dashed dashed solid; margin-top: -14px; position: absolute; left: 0px; top: 15px; } ''' % border_color) pointer_wdg.add(style) if menu: from tactic.ui.panel import SimpleSideBarWdg simple_sidebar = SimpleSideBarWdg(view=menu, search_type="SidebarWdg", target=target) menu_wdg.add(simple_sidebar) else: style = self.get_style() top.add(style) self.view = 'tab' config = WidgetConfig.get(view=self.view, xml=config_xml) element_names = config.get_element_names() if not element_names: outer_wdg.add_style("display: none") if not state_value: if not element_names: state_value = "" else: state_value = element_names[0] for element_name in element_names: item_div = DivWdg() menu_wdg.add(item_div) item_div.add_class("spt_switcher_item") item_div.add_class("tactic_hover") item_div.add_style("width: 100%") attrs = config.get_element_attributes(element_name) title = attrs.get("title") if not title: title = Common.get_display_title(element_name) for name, value in attrs.items(): if name in ['title', 'class']: continue item_div.add_attr(name, value) css_class = attrs.get("class") if css_class: item_div.add_class(css_class) item_div.add(title) item_div.add_attr("spt_title", title) target = attrs.get("target") if not target: target = "spt_content" display_class = config.get_display_handler(element_name) display_options = config.get_display_options(element_name) if show_first != False: if element_name == state_value: item_div.add_behavior( { 'type': 'load', 'cbjs_action': ''' bvr.src_el.click(); ''' } ) if display_class: item_div.add_behavior( { 'type': 'click_up', 'display_class': display_class, 'display_options': display_options, 'element_name': element_name, 'target': target, 'save_state': save_state, 'cbjs_action': ''' var menu_item = bvr.src_el; var top = menu_item.getParent(".spt_switcher_top"); var menu = menu_item.getParent(".spt_switcher_menu"); // Get target class var target_class = bvr.target; if (target_class.indexOf(".") != -1) { var parts = target_class.split("."); target_class = parts[1]; target_top_class = parts[0]; } else { target_top_class = null; } if (target_top_class) { var target_top = bvr.src_el.getParent("."+target_top_class); } else { var target_top = $(document.body); } var target = target_top.getElement("."+target_class); if (target) { spt.panel.load(target, bvr.display_class, bvr.display_options); } menu.setStyle("display", "none"); top.removeClass("spt_selected"); var title = bvr.src_el.getAttribute("spt_title"); var title_el = top.getElement(".spt_title"); if (title_el) title_el.innerHTML = title if (bvr.save_state) { var server = TacticServerStub.get() server.set_widget_setting(bvr.save_state, bvr.element_name); } ''' } ) return top
def get_display(my): top = my.top top.add_class("spt_sandbox_select_top") sandbox_options = [ { 'name': 'fast', 'base_dir': 'C:/Fast', }, { 'name': 'faster', 'base_dir': 'C:/Faster', }, { 'name': 'slow', 'base_dir': 'Z:/Slow', } ] process = my.kwargs.get("process") search_key = my.kwargs.get("search_key") sobject = Search.get_by_search_key(search_key) search_type = sobject.get_base_search_type() client_os = Environment.get_env_object().get_client_os() if client_os == 'nt': prefix = "win32" else: prefix = "linux" alias_dict = Config.get_dict_value("checkin", "%s_sandbox_dir" % prefix) search_key = sobject.get_search_key() key = "sandbox_dir:%s" % search_key from pyasm.web import WidgetSettings value = WidgetSettings.get_value_by_key(key) sandboxes_div = DivWdg() top.add(sandboxes_div) sandboxes_div.add_relay_behavior( { 'type': 'mouseenter', 'bvr_match_class': 'spt_sandbox_option', 'cbjs_action': ''' var last_background = bvr.src_el.getStyle("background-color"); bvr.src_el.setAttribute("spt_last_background", last_background); bvr.src_el.setStyle("background-color", "#E0E0E0"); bvr.src_el.setStyle("opacity", "1.0"); ''' } ) sandboxes_div.add_relay_behavior( { 'type': 'mouseleave', 'bvr_match_class': 'spt_sandbox_option', 'cbjs_action': ''' var last_background = bvr.src_el.getAttribute("spt_last_background"); bvr.src_el.setStyle("background-color", last_background); if (!bvr.src_el.hasClass("spt_selected")) { bvr.src_el.setStyle("opacity", "0.5"); } ''' } ) sandboxes_div.add_relay_behavior( { 'type': 'mouseup', 'key': key, 'bvr_match_class': 'spt_sandbox_option', 'cbjs_action': ''' var sandbox_dir = bvr.src_el.getAttribute("spt_sandbox_dir"); var server = TacticServerStub.get(); server.set_widget_setting(bvr.key, sandbox_dir); var applet = spt.Applet.get(); applet.makedirs(sandbox_dir); //var top = bvr.src_el.getParent(".spt_sandbox_select_top"); var top = bvr.src_el.getParent(".spt_checkin_top"); spt.panel.refresh(top); ''' } ) #search = Search("config/naming") #search.add_filter("search_type", search_type) #search.add_filter("process", process) #namings = search.get_sobjects() #naming = namings[0] from pyasm.biz import Snapshot, Naming virtual_snapshot = Snapshot.create_new() virtual_snapshot.set_value("process", process) # for purposes of the sandbox folder for the checkin widget, # the context is the process virtual_snapshot.set_value("context", process) naming = Naming.get(sobject, virtual_snapshot) if naming: naming_expr = naming.get_value("sandbox_dir_naming") alias_options = naming.get_value("sandbox_dir_alias") else: naming_expr = None alias_options = None if alias_options == "__all__": alias_options = alias_dict.keys() elif alias_options: alias_options = alias_options.split("|") else: alias_options = ['default'] for alias in alias_options: from pyasm.biz import DirNaming dir_naming = DirNaming(sobject=sobject, snapshot=virtual_snapshot) dir_naming.set_protocol("sandbox") dir_naming.set_naming(naming_expr) base_dir = dir_naming.get_dir(alias=alias) sandbox_div = DivWdg() sandboxes_div.add(sandbox_div) sandbox_div.add_class("spt_sandbox_option") sandbox_div.add_attr("spt_sandbox_dir", base_dir) if value == base_dir: sandbox_div.add_color("background", "background3") #sandbox_div.set_box_shadow() sandbox_div.add_class("spt_selected") else: sandbox_div.add_style("opacity", "0.5") sandbox_div.add_style("width: auto") sandbox_div.add_style("height: 55px") sandbox_div.add_style("padding: 5px") #sandbox_div.add_style("float: left") sandbox_div.add_style("margin: 15px") sandbox_div.add_border() if alias: alias_div = DivWdg() sandbox_div.add(alias_div) alias_div.add(alias) alias_div.add_style("font-size: 1.5em") alias_div.add_style("font-weight: bold") alias_div.add_style("margin-bottom: 15px") icon_wdg = IconWdg("Folder", IconWdg.FOLDER) sandbox_div.add(icon_wdg) sandbox_div.add(base_dir) return top
def init(my): my.user_override = my.kwargs.get('user_override') in ['true', True] custom_search_view = my.kwargs.get('custom_search_view') if not custom_search_view or not custom_search_view.strip(): custom_search_view = 'search' # create a search for this search widget my.search_type = my.kwargs.get('search_type') my.search = Search(my.search_type) my.config = None # determine whether or not to use the last search. If any kind of # state has been set, then ignore the last_search my.use_last_search = True parent_key = my.kwargs.get('parent_key') state = my.kwargs.get('state') if parent_key or state or my.kwargs.get('use_last_search') == False: my.use_last_search = False my.prefix_namespace = my.kwargs.get('prefix_namespace') # NOTE: this is still hard coded my.prefix = 'main_body' # if we are asking for a specific saved search save = my.kwargs.get('save') my.view = my.kwargs.get('view') # get the config from a specific location # if the view is specified, use this view with the values # specified explicitly in this view my.config = None # see if a filter is explicitly passed in filter = my.kwargs.get('filter') my.limit = my.kwargs.get('limit') my.run_search_bvr = my.kwargs.get('run_search_bvr') # get from search view # filter can be either dict(data) or a list or # xml(filter wdg definition) if filter: if type(filter) == types.DictType: my.config = my.get_default_filter_config() filter_data = FilterData([filter]) filter_data.set_to_cgi() elif type(filter) == types.ListType: my.config = my.get_default_filter_config() filter_data = FilterData(filter) filter_data.set_to_cgi() else: try: filter_data = None # TODO: remove this. This is for backward compatibilty my.config = WidgetConfig.get(xml=filter, view='filter') filter_data = FilterData.get() if not filter_data.get_data(): # use widget settings key = SearchWdg._get_key(my.search_type, my.view) data = WidgetSettings.get_value_by_key(key) if data: filter_data = FilterData(data) filter_data.set_to_cgi() except XmlException, e: print "WARNING: non-xml filter detected!! %s" %filter
def get_display(my): top = my.top top.add_class("spt_branch_content") my.set_as_panel(top) top.add_color("color", "color") top.add_color("background", "background") #top.add_border() #top.add_style("padding", "10px") top.add_style("min-width: 600px") top.add_style("min-height: 400px") top.add_behavior( { 'type': 'load', 'cbjs_action': scm_get_onload_js() } ) sync_dir = Environment.get_sandbox_dir() project = Project.get() depot = project.get_value("location", no_exception=True) if not depot: depot = project.get_code() location = '//%s' % depot branch = my.kwargs.get("branch") if not branch: branch = WidgetSettings.get_value_by_key("current_branch") else: WidgetSettings.set_value_by_key("current_branch", branch) if not branch: branch = 'main' branches = my.kwargs.get("branches") if not branches: branches = [] elif isinstance(branches, basestring): branches = branches.replace("'", '"') branches = jsonloads(branches) top.add_behavior( { 'type': 'load', 'depot': depot, 'sync_dir': sync_dir, 'cbjs_action': ''' spt.scm.sync_dir = bvr.sync_dir; spt.scm.depot = bvr.depot; ''' } ) inner = DivWdg() top.add(inner) table = Table() inner.add(table) table.add_style("width: 100%") table.add_row() th = table.add_header("") th = table.add_header("Branches") th.add_style("text-align: left") th = table.add_header("Options") th.add_style("text-align: left") th = table.add_header("Owner") th.add_style("text-align: left") th = table.add_header("Check-out") th.add_style("text-align: left") bgcolor = table.get_color("background", -8) table.add_relay_behavior( { 'type': 'mouseover', 'bvr_match_class': 'spt_branch_item', 'bgcolor': bgcolor, 'cbjs_action': ''' bvr.src_el.setStyle("background-color", bvr.bgcolor); ''' } ) table.add_relay_behavior( { 'type': 'mouseout', 'bvr_match_class': 'spt_branch_item', 'cbjs_action': ''' bvr.src_el.setStyle("background-color", ''); ''' } ) table.add_relay_behavior( { 'type': 'mouseup', 'bvr_match_class': "spt_branch_radio", 'cbjs_action': ''' var value = bvr.src_el.value; spt.app_busy.show("Setting current branch to " + value); var server = TacticServerStub.get(); server.set_widget_setting("current_branch", value); var top = bvr.src_el.getParent(".spt_checkin_top"); top.removeAttribute("spt_sandbox_dir"); spt.panel.refresh(top); spt.app_busy.hide(); ''' } ) for c in branches: name = c.get("branch") tr = table.add_row() tr.add_class("spt_branch_item") radio = RadioWdg("branch") radio.add_class("spt_branch_radio") table.add_cell(radio) radio.set_option("value", name) if name == branch: radio.set_checked() table.add_cell(name) table.add_cell(c.get("Options")) table.add_cell(c.get("Owner")) icon = IconButtonWdg(title="Check-out", icon=IconWdg.CHECK_OUT_SM) table.add_cell(icon) icon.add_behavior( { 'type': 'click_up', 'branch': c.get("branch"), 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_branch_content"); top.setAttribute("spt_brange", bvr.branch); spt.app_busy.show("Checking out branch ["+bvr.branch+"]"); spt.scm.checkout("new_project/"+bvr.branch); spt.app_busy.hide(); ''' } ) inner.add("<hr/>") if my.kwargs.get("branches") == None: inner.add_behavior( { 'type': 'load', 'location': location, 'sync_dir': sync_dir, 'cbjs_action': ''' spt.branch = {} spt.branch.load = function(el) { var branches = spt.scm.run("get_branches",[]); var class_name = 'tactic.ui.checkin.branch_wdg.BranchWdg'; var kwargs = { branches: branches, } var top = el.getParent(".spt_branch_content"); spt.panel.load(top, class_name, kwargs); } spt.branch.load(bvr.src_el); ''' } ) return top
def init(my): my.user_override = my.kwargs.get('user_override') in ['true', True] custom_search_view = my.kwargs.get('custom_search_view') if not custom_search_view or not custom_search_view.strip(): custom_search_view = 'search' # create a search for this search widget my.search_type = my.kwargs.get('search_type') my.search = Search(my.search_type) my.config = None # determine whether or not to use the last search. If any kind of # state has been set, then ignore the last_search my.use_last_search = True parent_key = my.kwargs.get('parent_key') state = my.kwargs.get('state') if parent_key or state or my.kwargs.get('use_last_search') == False: my.use_last_search = False my.prefix_namespace = my.kwargs.get('prefix_namespace') # NOTE: this is still hard coded my.prefix = 'main_body' # if we are asking for a specific saved search save = my.kwargs.get('save') my.view = my.kwargs.get('view') # get the config from a specific location # if the view is specified, use this view with the values # specified explicitly in this view my.config = None # see if a filter is explicitly passed in filter = my.kwargs.get('filter') my.limit = my.kwargs.get('limit') my.run_search_bvr = my.kwargs.get('run_search_bvr') # get from search view # filter can be either dict(data) or a list or # xml(filter wdg definition) if filter: if type(filter) == types.DictType: my.config = my.get_default_filter_config() filter_data = FilterData([filter]) filter_data.set_to_cgi() elif type(filter) == types.ListType: my.config = my.get_default_filter_config() filter_data = FilterData(filter) filter_data.set_to_cgi() else: try: filter_data = None # TODO: remove this. This is for backward compatibilty my.config = WidgetConfig.get(xml=filter, view='filter') filter_data = FilterData.get() if not filter_data.get_data(): # use widget settings key = SearchWdg._get_key(my.search_type, my.view) data = WidgetSettings.get_value_by_key(key) if data: filter_data = FilterData(data) filter_data.set_to_cgi() except XmlException, e: print "WARNING: non-xml filter detected!! %s" % filter
def init(self): self.user_override = self.kwargs.get('user_override') in ['true', True] custom_search_view = self.kwargs.get('custom_search_view') if not custom_search_view or not custom_search_view.strip(): custom_search_view = 'search' # create a search for this search widget self.search_type = self.kwargs.get('search_type') self.search = self.kwargs.get("search") if not self.search: self.search = Search(self.search_type) self.config = None # determine whether or not to use the last search. If any kind of # state has been set, then ignore the last_search self.use_last_search = True parent_key = self.kwargs.get('parent_key') state = self.kwargs.get('state') if parent_key or state or self.kwargs.get('use_last_search') in [False, 'false']: self.use_last_search = False self.prefix_namespace = self.kwargs.get('prefix_namespace') # NOTE: this is still hard coded self.prefix = 'main_body' # if we are asking for a specific saved search save = self.kwargs.get('save') self.view = self.kwargs.get('view') # get the config from a specific location # if the view is specified, use this view with the values # specified explicitly in this view self.config = None # see if a filter is explicitly passed in filter = self.kwargs.get('filter') self.limit = self.kwargs.get('limit') self.run_search_bvr = self.kwargs.get('run_search_bvr') # get from search view # filter can be either dict(data) or a list or # xml(filter wdg definition) if filter: if type(filter) == types.DictType: self.config = self.get_default_filter_config() filter_data = FilterData([filter]) filter_data.set_to_cgi() elif type(filter) == types.ListType: self.config = self.get_default_filter_config() filter_data = FilterData(filter) filter_data.set_to_cgi() else: try: filter_data = None # TODO: remove this. This is for backward compatibilty self.config = WidgetConfig.get(xml=filter, view='filter') filter_data = FilterData.get() if not filter_data.get_data(): # use widget settings key = SearchWdg._get_key(self.search_type, self.view) data = WidgetSettings.get_value_by_key(key) if data: filter_data = FilterData(data) filter_data.set_to_cgi() except XmlException as e: print("WARNING: non-xml filter detected!!") # NOTE: this is only used to maintain backwards compatibility # plus it is needed for link_search: which contains the filter_config (old way of doing it) if not self.config:# and self.view: """ if ':' in self.view: # avoid view of a SearchWdg like link_search:<search_type>:<view> search_view = custom_search_view else: search_view = self.view """ search_view = custom_search_view config_view = WidgetConfigView.get_by_search_type(self.search_type, view=search_view) # get the self.config first for the display of SearchWdg # then get the filter data below if there is any if config_view.get_config().has_view(search_view): self.config = config_view.get_config() try: search = Search('config/widget_config') search.add_filter("view", self.view) search.add_filter("search_type", self.search_type) config_sobjs = search.get_sobjects() from pyasm.search import WidgetDbConfig config_sobj = WidgetDbConfig.merge_configs(config_sobjs) #config_sobj = config_sobjs[0] except SearchException as e: print("WARNING: ", e) config_sobj = None if config_sobj: config_xml = config_sobj.get_xml_value("config") if not config_view.get_config().has_view(self.view): # make sure it does have the old way of storing filter # elements instead of just filter data if config_xml.get_nodes("config/filter/element"): self.config = WidgetConfig.get(xml=config_xml, view='filter') #self.config = self.get_default_filter_config() # set the form variables for the filters data = config_xml.get_value("config/filter/values") # link_search with specific search params takes precesdence # TODO: make a distinction between search definition and alter # search data provided by user if data and not self.user_override: filter_data = FilterData(data) filter_data.set_to_cgi() else: self.set_filter_data(self.search_type, self.view) else: if self.use_last_search: self.set_filter_data(self.search_type, self.view) if not self.config: # get the approprate filter definition self.config = self.get_default_filter_config() if self.use_last_search: self.set_filter_data(self.search_type, self.view) if not self.config: return self.num_filters_enabled = 0 # create the filters self.filters = [] security = Environment.get_security() element_names = self.config.get_element_names() #element_names = ["Keywords", "Related"] for element_name in element_names: filter = self.config.get_display_widget(element_name) if filter and filter.is_visible(): self.filters.append(filter) # make sure there is at least one filter defined #assert self.filters # just for drawing purpose if self.kwargs.get('skip_search') == True: return try: self.alter_search() self.set_persistent_value() except SearchInputException as e: self.clear_search_data(self.search_type) raise SearchInputException("%s If this problem persists, this view may contain invalid data in < values >. Clean up the data in Widget Config for the view [%s]."%( e.__str__(), self.view)) except: self.clear_search_data(self.search_type) raise
def add_top_behaviors(my, top): super(ScmDirListWdg, my).add_top_behaviors(top) changelist = WidgetSettings.get_value_by_key("current_changelist") menu_item = MenuItem(type='title', label="Perforce Actions") my.menu.add(menu_item) menu_item = MenuItem(type='action', label='Add To Changelist [%s]' % changelist) my.menu.add(menu_item) menu_item.add_behavior({ 'type': 'click_up', 'changelist': changelist, 'cbjs_action': ''' var activator = spt.smenu.get_activator(bvr); var paths = spt.checkin.get_selected_paths(); if (paths.length == 0) { var path = activator.getAttribute("spt_path"); paths = [path] } var changelist = bvr.changelist; // TODO: optimize this to call on once by passing in the array // of paths for (var i = 0; i < paths.length; i++) { var path = paths[i]; spt.scm.run("add", [path, changelist]); } var top = activator.getParent(".spt_checkin_top"); spt.panel.refresh(top); ''' }) menu_item = MenuItem(type='action', label='Make Editable') my.menu.add(menu_item) menu_item.add_behavior({ 'type': 'click_up', 'changelist': changelist, 'cbjs_action': ''' var activator = spt.smenu.get_activator(bvr); var paths = spt.checkin.get_selected_paths(); if (paths.length == 0) { var path = activator.getAttribute("spt_path"); paths = [path] } // TODO: optimize this to call on once by passing in the array // of paths for (var i = 0; i < paths.length; i++) { var path = paths[i]; spt.scm.run("edit", [path, bvr.changelist]); } var top = activator.getParent(".spt_checkin_top"); spt.panel.refresh(top); ''' }) menu_item = MenuItem(type='action', label='Revert File') my.menu.add(menu_item) menu_item.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var activator = spt.smenu.get_activator(bvr); var path = activator.getAttribute("spt_path"); try { spt.scm.revert(path); var top = activator.getParent(".spt_checkin_top"); spt.panel.refresh(top); } catch (e) { spt.scm.handle_error(e); } ''' }) menu_item = MenuItem(type='action', label='File Log') my.menu.add(menu_item) menu_item.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var activator = spt.smenu.get_activator(bvr); var path = activator.getAttribute("spt_path"); try { var file_logs = spt.scm.file_log(path); var class_name = 'tactic.ui.checkin.ScmCheckinHistoryWdg'; var kwargs = { 'file_logs': file_logs } spt.panel.load_popup("Check-in History", class_name, kwargs); } catch (e) { spt.scm.handle_error(e); } ''' })
def get_display(my): top = my.top top.add_class("spt_changelist_content") my.set_as_panel(top) top.add_color("color", "color") top.add_color("background", "background") #top.add_border() #top.add_style("padding", "10px") top.add_style("min-width: 600px") top.add_style("min-height: 400px") top.add_behavior({'type': 'load', 'cbjs_action': scm_get_onload_js()}) sync_dir = Environment.get_sandbox_dir() # HARD CODED project = Project.get() depot = project.get_value("location", no_exception=True) if not depot: depot = project.get_code() location = '//%s' % depot changelist = my.kwargs.get("changelist") if not changelist: changelist = WidgetSettings.get_value_by_key("current_changelist") else: WidgetSettings.set_value_by_key("current_changelist", changelist) if not changelist: changelist = 'default' changelists = my.kwargs.get("changelists") if not changelists: changelists = [] elif isinstance(changelists, basestring): changelists = changelists.replace("'", '"') changelists = jsonloads(changelists) top.add_behavior({ 'type': 'load', 'sync_dir': sync_dir, 'depot': depot, 'cbjs_action': ''' spt.scm.sync_dir = bvr.sync_dir; spt.scm.depot = bvr.depot; ''' }) inner = DivWdg() top.add(inner) table = Table() inner.add(table) table.add_style("width: 100%") table.add_color("background", "background", -3) table.add_row() th = table.add_header("") th = table.add_header("Changelist") th.add_style("text-align: left") th = table.add_header("Description") th.add_style("text-align: left") th = table.add_header("# Items") th.add_style("text-align: left") th = table.add_header("Status") th.add_style("text-align: left") th = table.add_header("View") th.add_style("text-align: left") th = table.add_header("Delete") th.add_style("text-align: left") #table.set_unique_id() #table.add_smart_styles("spt_changelist_item", { # 'text-align: right' # } )) bgcolor = table.get_color("background", -8) table.add_relay_behavior({ 'type': 'mouseover', 'bvr_match_class': 'spt_changelist_item', 'bgcolor': bgcolor, 'cbjs_action': ''' bvr.src_el.setStyle("background-color", bvr.bgcolor); ''' }) table.add_relay_behavior({ 'type': 'mouseout', 'bvr_match_class': 'spt_changelist_item', 'cbjs_action': ''' bvr.src_el.setStyle("background-color", ''); ''' }) table.add_relay_behavior({ 'type': 'mouseup', 'bvr_match_class': "spt_changelist_radio", 'cbjs_action': ''' var changelist = bvr.src_el.value; var top = bvr.src_el.getParent(".spt_changelist_content"); top.setAttribute("spt_changelist", changelist); spt.app_busy.show("Loading Changelists Information"); spt.changelist.load(bvr.src_el, changelist); spt.app_busy.hide(); ''' }) for c in changelists: num_items = len(c.get("info")) name = c.get("change") tr = table.add_row() tr.add_class("spt_changelist_item") radio = RadioWdg("changelist") radio.add_class("spt_changelist_radio") table.add_cell(radio) radio.set_option("value", name) if name == changelist: radio.set_checked() table.add_cell(name) table.add_cell(c.get("desc")) table.add_cell(num_items) table.add_cell(c.get("status")) if num_items: icon = IconButtonWdg(title="View", icon=IconWdg.ZOOM) icon.add_behavior({ 'type': 'click_up', 'changelist': c.get("change"), 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_changelist_content"); top.setAttribute("spt_changelist", bvr.changelist); spt.app_busy.show("Loading Changelist"); spt.changelist.load(bvr.src_el, bvr.changelist); spt.app_busy.hide(); ''' }) else: icon = '' table.add_cell(icon) if not num_items and name != 'default': icon = IconButtonWdg(title="Delete Changelist", icon=IconWdg.DELETE) else: icon = "" table.add_cell(icon) inner.add("<hr/>") files = my.kwargs.get("files") if isinstance(files, basestring): files = files.replace("'", '"') files = jsonloads(files) if files == None: inner.add_behavior({ 'type': 'load', 'location': location, 'changelist': changelist, 'sync_dir': sync_dir, 'cbjs_action': ''' spt.changelist = {} spt.changelist.load = function(el, changelist) { var applet = spt.Applet.get(); var changelists = spt.scm.run("get_changelists_by_user",[]); var dflt = { 'change': 'default', 'status': 'pending' } changelists.push(dflt); changelists = changelists.reverse(); for (var i = 0; i < changelists.length; i++) { var info = spt.scm.run("get_changelist_files",[changelists[i].change]); changelists[i]['info'] = info; } // get the current chnage list var files = spt.scm.run("get_changelist_files",[changelist]); var path_info = {}; var sizes = []; for ( var i = 0; i < files.length; i++) { // FIXME: perforce specific var path = files[i].depotFile; path = path.replace(bvr.location, bvr.sync_dir); files[i].path = path; var size; if (applet.exists(path)) { var info = applet.get_path_info(path); size = info.size; } else { size = 0; } sizes.push(size); path_info[path] = 'editable'; } //var ret_val = spt.scm.status(bvr.sync_dir); //console.log(ret_val); var class_name = 'tactic.ui.checkin.changelist_wdg.ChangelistWdg'; var kwargs = { files: files, sizes: sizes, changelist: changelist, changelists: changelists, path_info: path_info, } var top = el.getParent(".spt_changelist_content"); spt.panel.load(top, class_name, kwargs); } spt.changelist.load(bvr.src_el, bvr.changelist); ''' }) content = DivWdg() inner.add(content) content.add_class("spt_changelist_content") if files == None: loading_wdg = DivWdg() content.add(loading_wdg) loading_wdg.add("<b>Loading ...</b>") loading_wdg.add_style("padding: 30px") elif files: title_wdg = DivWdg() title_wdg.add_style("height: 15px") title_wdg.add("Changelist: [%s]" % changelist) content.add(title_wdg) title_wdg.add_gradient("background", "background", -5) title_wdg.add_style("padding: 5px") title_wdg.add_border() #button = SingleButtonWdg(tip='Add New Changelist', icon=IconWdg.ADD) #content.add(button) content.add("<br/>") paths = [x.get("path") for x in files] sizes = my.kwargs.get("sizes") path_info = my.kwargs.get("path_info") from scm_dir_list_wdg import ScmDirListWdg # dummy search_key search_key = "sthpw/virtual?code=xx001" dir_list_wdg = ScmDirListWdg( base_dir=sync_dir, paths=paths, sizes=sizes, path_info=path_info, all_open=True, #search_key=search_key ) content.add(dir_list_wdg) else: content.add("Changelist: [%s]" % changelist) content.add("<br/>" * 2) no_files_wdg = DivWdg() content.add(no_files_wdg) no_files_wdg.add_style("padding: 20px") no_files_wdg.add_border() no_files_wdg.add("No files in changelist") no_files_wdg.add_color("color", "color3") no_files_wdg.add_color("background", "background3") no_files_wdg.add_style("font-weight: bold") no_files_wdg.add_style("text-align: center") return top
def get_display(self): top = self.top top.add_class("spt_switcher_top") ''' This supports supports two menu definitions: menu - specifies a view for SideBarWdg which will be ingected as menu config_xml - specifies menu entries. For example: <display class="tactic.ui.widget.LayoutSwitcherWdg"> <!-- config_xml --> <config> <!-- Menu item 1 --> <element name="self_tasks_default" title="My Tasks" target=spt_my_tasks_table_top"> <display class="tactic.ui.panel.ViewPanelWdg"> <search_type>sthpw/task</search_type> <show_shelf>false</show_shelf> <view>my_tasks_default</view> </display> </element> <!-- Menu item 2 --> <element ... > <display ... > </display> </element> </config> </display> target - specifies target div to load views when using "menu" kwarg use_href - updates address bar hash (this is TODO) ''' menu = self.kwargs.get("menu") config_xml = self.kwargs.get("config_xml") target = self.kwargs.get("target") #default default_layout = self.kwargs.get("default_layout") # find the save state value, if state is to be saved save_state = self.kwargs.get("save_state") if save_state in [False, 'false']: save_state = None show_first = False else: show_first = True state_value = None if save_state: state_value = WidgetSettings.get_value_by_key(save_state) elif default_layout: state_value = default_layout title = self.kwargs.get("title") if not title and state_value: title = state_value if not title: title = "Switch Layout" mode = self.kwargs.get("mode") if mode == "button": color = self.kwargs.get("color") or "default" activator = DivWdg( "<button class='btn btn-%s dropdown-toggle' style='width: 160px'><span class='spt_title'>%s</span> <span class='caret'></span></button>" % (color, title)) elif mode == "div": color = self.kwargs.get("color") or "" background = self.kwargs.get("background") or "transparent" activator = DivWdg( "<button class='btn dropdown-toggle' style='width: 160px; background: %s; color: %s; font-weight: bold'><span class='spt_title'>%s</span> <span class='caret'></span></button>" % (background, color, title)) else: activator = IconButtonWdg(name="Layout Switcher", icon="BS_TH_LIST") top.add(activator) activator.add_class("spt_switcher_activator") activator.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var activator = bvr.src_el; var top = activator.getParent(".spt_switcher_top"); var menu = top.getElement(".spt_switcher_menu"); if (top.hasClass("spt_selected")) { top.removeClass("spt_selected"); menu.setStyle("display", "none"); } else { top.addClass("spt_selected"); menu.setStyle("display", ""); var pos = activator.getPosition(); var button_size = activator.getSize(); var menu_size = menu.getSize(); var offset = { x: button_size.x - menu_size.x, y: button_size.y } menu.position({position: 'upperleft', relativeTo: activator, offset: offset}); spt.body.add_focus_element(menu); var pointer = menu.getElement(".spt_switcher_popup_pointer"); pointer.setStyle("margin-left", menu_size.x - button_size.x); } ''' }) outer_wdg = DivWdg() top.add(outer_wdg) # menu_wdg menu_wdg = DivWdg() outer_wdg.add(menu_wdg) menu_wdg.add_color("color", "color") menu_wdg.add_color("background", "background") menu_wdg.add_border() menu_wdg.add_class("spt_switcher_menu") menu_wdg.add_style("display: none") menu_wdg.add_style("margin-top", "20px") menu_wdg.add_style("position", "absolute") menu_wdg.add_style("z-index", "101") menu_wdg.add_behavior({ 'type': 'mouseleave', 'cbjs_action': ''' var menu = bvr.src_el; var top = menu.getParent(".spt_switcher_top"); top.removeClass("spt_selected"); menu.setStyle("display", "none") ''' }) border_color = menu_wdg.get_color("border") # Pointer under activator pointer_wdg = DivWdg() menu_wdg.add(pointer_wdg) pointer_wdg.add(''' <div class="spt_switcher_first_arrow_div"> </div> <div class="spt_switcher_second_arrow_div"> </div> ''') pointer_wdg.add_class("spt_switcher_popup_pointer") style = HtmlElement.style(''' .spt_switcher_menu .spt_switcher_popup_pointer { z-index: 10; position: absolute; top: -15px; right: 15px; } .spt_switcher_menu .spt_switcher_first_arrow_div { border-color: rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) %s; top: -15px; z-index: 1; border-width: 0 15px 15px; height: 0; width: 0; border-style: dashed dashed solid; left: 15px; } .spt_switcher_menu .spt_switcher_second_arrow_div{ border-color: rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) #fff; z-index: 1; border-width: 0 15px 15px; height: 0; width: 0; border-style: dashed dashed solid; margin-top: -14px; position: absolute; left: 0px; top: 15px; } ''' % border_color) pointer_wdg.add(style) if menu: from tactic.ui.panel import SimpleSideBarWdg simple_sidebar = SimpleSideBarWdg(view=menu, search_type="SidebarWdg", target=target) menu_wdg.add(simple_sidebar) else: style = self.get_style() top.add(style) self.view = 'tab' config = WidgetConfig.get(view=self.view, xml=config_xml) element_names = config.get_element_names() if not element_names: outer_wdg.add_style("display: none") if not state_value: if not element_names: state_value = "" else: state_value = element_names[0] for element_name in element_names: item_div = DivWdg() menu_wdg.add(item_div) item_div.add_class("spt_switcher_item") item_div.add_class("tactic_hover") item_div.add_style("width: 100%") attrs = config.get_element_attributes(element_name) title = attrs.get("title") if not title: title = Common.get_display_title(element_name) for name, value in attrs.items(): if name in ['title', 'class']: continue item_div.add_attr(name, value) css_class = attrs.get("class") if css_class: item_div.add_class(css_class) item_div.add(title) item_div.add_attr("spt_title", title) target = attrs.get("target") if not target: target = "spt_content" display_class = config.get_display_handler(element_name) display_options = config.get_display_options(element_name) if show_first != False: if element_name == state_value: item_div.add_behavior({ 'type': 'load', 'cbjs_action': ''' bvr.src_el.click(); ''' }) if display_class: item_div.add_behavior({ 'type': 'click_up', 'display_class': display_class, 'display_options': display_options, 'element_name': element_name, 'target': target, 'save_state': save_state, 'cbjs_action': ''' var menu_item = bvr.src_el; var top = menu_item.getParent(".spt_switcher_top"); var menu = menu_item.getParent(".spt_switcher_menu"); // Get target class var target_class = bvr.target; if (target_class.indexOf(".") != -1) { var parts = target_class.split("."); target_class = parts[1]; target_top_class = parts[0]; } else { target_top_class = null; } if (target_top_class) { var target_top = bvr.src_el.getParent("."+target_top_class); } else { var target_top = $(document.body); } var target = target_top.getElement("."+target_class); if (target) { spt.panel.load(target, bvr.display_class, bvr.display_options); } menu.setStyle("display", "none"); top.removeClass("spt_selected"); var title = bvr.src_el.getAttribute("spt_title"); var title_el = top.getElement(".spt_title"); if (title_el) title_el.innerHTML = title if (bvr.save_state) { var server = TacticServerStub.get() server.set_widget_setting(bvr.save_state, bvr.element_name); } ''' }) return top
def get_display(my): top = my.top top.add_class("spt_changelist_content") my.set_as_panel(top) top.add_color("color", "color") top.add_color("background", "background") #top.add_border() #top.add_style("padding", "10px") top.add_style("min-width: 600px") top.add_style("min-height: 400px") top.add_behavior( { 'type': 'load', 'cbjs_action': scm_get_onload_js() } ) sync_dir = Environment.get_sandbox_dir() # HARD CODED project = Project.get() depot = project.get_value("location", no_exception=True) if not depot: depot = project.get_code() location = '//%s' % depot changelist = my.kwargs.get("changelist") if not changelist: changelist = WidgetSettings.get_value_by_key("current_changelist") else: WidgetSettings.set_value_by_key("current_changelist", changelist) if not changelist: changelist = 'default' changelists = my.kwargs.get("changelists") if not changelists: changelists = [] elif isinstance(changelists, basestring): changelists = changelists.replace("'", '"') changelists = jsonloads(changelists) top.add_behavior( { 'type': 'load', 'sync_dir': sync_dir, 'depot': depot, 'cbjs_action': ''' spt.scm.sync_dir = bvr.sync_dir; spt.scm.depot = bvr.depot; ''' } ) inner = DivWdg() top.add(inner) table = Table() inner.add(table) table.add_style("width: 100%") table.add_color("background", "background", -3) table.add_row() th = table.add_header("") th = table.add_header("Changelist") th.add_style("text-align: left") th = table.add_header("Description") th.add_style("text-align: left") th = table.add_header("# Items") th.add_style("text-align: left") th = table.add_header("Status") th.add_style("text-align: left") th = table.add_header("View") th.add_style("text-align: left") th = table.add_header("Delete") th.add_style("text-align: left") #table.set_unique_id() #table.add_smart_styles("spt_changelist_item", { # 'text-align: right' # } )) bgcolor = table.get_color("background", -8) table.add_relay_behavior( { 'type': 'mouseover', 'bvr_match_class': 'spt_changelist_item', 'bgcolor': bgcolor, 'cbjs_action': ''' bvr.src_el.setStyle("background-color", bvr.bgcolor); ''' } ) table.add_relay_behavior( { 'type': 'mouseout', 'bvr_match_class': 'spt_changelist_item', 'cbjs_action': ''' bvr.src_el.setStyle("background-color", ''); ''' } ) table.add_relay_behavior( { 'type': 'mouseup', 'bvr_match_class': "spt_changelist_radio", 'cbjs_action': ''' var changelist = bvr.src_el.value; var top = bvr.src_el.getParent(".spt_changelist_content"); top.setAttribute("spt_changelist", changelist); spt.app_busy.show("Loading Changelists Information"); spt.changelist.load(bvr.src_el, changelist); spt.app_busy.hide(); ''' } ) for c in changelists: num_items = len(c.get("info")) name = c.get("change") tr = table.add_row() tr.add_class("spt_changelist_item") radio = RadioWdg("changelist") radio.add_class("spt_changelist_radio") table.add_cell(radio) radio.set_option("value", name) if name == changelist: radio.set_checked() table.add_cell(name) table.add_cell(c.get("desc")) table.add_cell(num_items) table.add_cell(c.get("status")) if num_items: icon = IconButtonWdg(title="View", icon=IconWdg.ZOOM) icon.add_behavior( { 'type': 'click_up', 'changelist': c.get("change"), 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_changelist_content"); top.setAttribute("spt_changelist", bvr.changelist); spt.app_busy.show("Loading Changelist"); spt.changelist.load(bvr.src_el, bvr.changelist); spt.app_busy.hide(); ''' } ) else: icon = '' table.add_cell(icon) if not num_items and name != 'default': icon = IconButtonWdg(title="Delete Changelist", icon=IconWdg.DELETE) else: icon = "" table.add_cell(icon) inner.add("<hr/>") files = my.kwargs.get("files") if isinstance(files, basestring): files = files.replace("'", '"') files = jsonloads(files) if files == None: inner.add_behavior( { 'type': 'load', 'location': location, 'changelist': changelist, 'sync_dir': sync_dir, 'cbjs_action': ''' spt.changelist = {} spt.changelist.load = function(el, changelist) { var applet = spt.Applet.get(); var changelists = spt.scm.run("get_changelists_by_user",[]); var dflt = { 'change': 'default', 'status': 'pending' } changelists.push(dflt); changelists = changelists.reverse(); for (var i = 0; i < changelists.length; i++) { var info = spt.scm.run("get_changelist_files",[changelists[i].change]); changelists[i]['info'] = info; } // get the current chnage list var files = spt.scm.run("get_changelist_files",[changelist]); var path_info = {}; var sizes = []; for ( var i = 0; i < files.length; i++) { // FIXME: perforce specific var path = files[i].depotFile; path = path.replace(bvr.location, bvr.sync_dir); files[i].path = path; var size; if (applet.exists(path)) { var info = applet.get_path_info(path); size = info.size; } else { size = 0; } sizes.push(size); path_info[path] = 'editable'; } //var ret_val = spt.scm.status(bvr.sync_dir); //console.log(ret_val); var class_name = 'tactic.ui.checkin.changelist_wdg.ChangelistWdg'; var kwargs = { files: files, sizes: sizes, changelist: changelist, changelists: changelists, path_info: path_info, } var top = el.getParent(".spt_changelist_content"); spt.panel.load(top, class_name, kwargs); } spt.changelist.load(bvr.src_el, bvr.changelist); ''' } ) content = DivWdg() inner.add(content) content.add_class("spt_changelist_content") if files == None: loading_wdg = DivWdg() content.add(loading_wdg) loading_wdg.add("<b>Loading ...</b>") loading_wdg.add_style("padding: 30px") elif files: title_wdg = DivWdg() title_wdg.add_style("height: 15px") title_wdg.add("Changelist: [%s]" % changelist) content.add(title_wdg) title_wdg.add_gradient("background", "background", -5) title_wdg.add_style("padding: 5px") title_wdg.add_border() #button = SingleButtonWdg(tip='Add New Changelist', icon=IconWdg.ADD) #content.add(button) content.add("<br/>") paths = [x.get("path") for x in files] sizes = my.kwargs.get("sizes") path_info = my.kwargs.get("path_info") from scm_dir_list_wdg import ScmDirListWdg # dummy search_key search_key = "sthpw/virtual?code=xx001" dir_list_wdg = ScmDirListWdg( base_dir=sync_dir, paths=paths, sizes=sizes, path_info=path_info, all_open=True, #search_key=search_key ) content.add(dir_list_wdg) else: content.add("Changelist: [%s]" % changelist) content.add("<br/>"*2) no_files_wdg = DivWdg() content.add(no_files_wdg) no_files_wdg.add_style("padding: 20px") no_files_wdg.add_border() no_files_wdg.add("No files in changelist") no_files_wdg.add_color("color", "color3") no_files_wdg.add_color("background", "background3") no_files_wdg.add_style("font-weight: bold") no_files_wdg.add_style("text-align: center") return top
def get_display(my): top = my.top top.add_class("spt_workspace_content") my.set_as_panel(top) top.add_color("color", "color") top.add_color("background", "background") top.add_style("min-width: 600px") top.add_style("min-height: 400px") # NOTE: is there ever a time when this is not loaded already? top.add_behavior( { 'type': 'load', 'cbjs_action': scm_get_onload_js() } ) sync_dir = Environment.get_sandbox_dir() project = Project.get() depot = project.get_value("location", no_exception=True) if not depot: depot = project.get_code() location = '//%s' % depot workspace = my.kwargs.get("workspace") if not workspace: workspace = WidgetSettings.get_value_by_key("current_workspace") else: WidgetSettings.set_value_by_key("current_workspace", workspace) if not workspace: workspace = 'main' workspaces = my.kwargs.get("workspaces") if not workspaces: workspaces = [] elif isinstance(workspaces, basestring): workspaces = workspaces.replace("'", '"') workspaces = jsonloads(workspaces) top.add_behavior( { 'type': 'load', 'depot': depot, 'sync_dir': sync_dir, 'cbjs_action': ''' spt.scm.sync_dir = bvr.sync_dir; spt.scm.depot = bvr.depot; ''' } ) inner = DivWdg() top.add(inner) table = Table() inner.add(table) table.add_style("width: 100%") table.add_row() th = table.add_header("") th = table.add_header("Workspaces") th.add_style("text-align: left") th = table.add_header("Description") th.add_style("text-align: left") th = table.add_header("Owner") th.add_style("text-align: left") th = table.add_header("Root") th.add_style("text-align: left") bgcolor = table.get_color("background", -8) table.add_relay_behavior( { 'type': 'mouseover', 'bvr_match_class': 'spt_workspace_item', 'bgcolor': bgcolor, 'cbjs_action': ''' bvr.src_el.setStyle("background-color", bvr.bgcolor); ''' } ) table.add_relay_behavior( { 'type': 'mouseout', 'bvr_match_class': 'spt_workspace_item', 'cbjs_action': ''' bvr.src_el.setStyle("background-color", ''); ''' } ) table.add_relay_behavior( { 'type': 'mouseup', 'bvr_match_class': "spt_workspace_radio", 'cbjs_action': ''' var value = bvr.src_el.value; spt.app_busy.show("Setting current workspace to " + value); var server = TacticServerStub.get(); server.set_widget_setting("current_workspace", value); var top = bvr.src_el.getParent(".spt_checkin_top"); top.removeAttribute("spt_sandbox_dir"); spt.panel.refresh(top); spt.app_busy.hide(); ''' } ) for c in workspaces: name = c.get("client") tr = table.add_row() tr.add_class("spt_workspace_item") radio = RadioWdg("workspace") radio.add_class("spt_workspace_radio") table.add_cell(radio) radio.set_option("value", name) if name == workspace: radio.set_checked() table.add_cell(name) table.add_cell(c.get("Description")) table.add_cell(c.get("Owner")) table.add_cell(c.get("Root")) if not workspaces: ws_div = DivWdg() table.add_row() table.add_cell(ws_div) ws_div.add_style("height: 60px") ws_div.add_style("width: 300px") ws_div.add("<b>No workspaces defined</b>") ws_div.add_color("color", "color3") ws_div.add_color("background", "background3") ws_div.add_border() ws_div.add_style("margin-top: 30px") ws_div.add_style("margin-bottom: 30px") ws_div.add_style("margin-left: auto") ws_div.add_style("margin-right: auto") ws_div.add_style("padding-top: 30px") ws_div.add_style("text-align: center") inner.add("<hr/>") if my.kwargs.get("workspaces") == None: inner.add_behavior( { 'type': 'load', 'location': location, 'sync_dir': sync_dir, 'cbjs_action': ''' spt.workspace = {} spt.workspace.load = function(el) { var workspaces = spt.scm.run("get_workspaces",[]); console.log(workspaces); var class_name = 'tactic.ui.checkin.workspace_wdg.WorkspaceWdg'; var kwargs = { workspaces: workspaces, } var top = el.getParent(".spt_workspace_content"); spt.panel.load(top, class_name, kwargs); } spt.workspace.load(bvr.src_el); ''' } ) return top