def get_data(my, sobject): values = [] labels = [] if not my.config: return values, labels for element in my.elements: options = my.config.get_display_options(element) attrs = my.config.get_element_attributes(element) label = attrs.get('title') if not label: label = Common.get_display_title(element) labels.append(label) expression = options.get("expression") if not expression: value = 0 else: value = Search.eval(expression, sobject, single=True) values.append(value) return values, labels
def get_related_wdg(my, aliases): div = DivWdg() div.add("<b>Related links</b>:  ") div.add_style("margin-top: 5px") div.add_style("margin-bottom: 5px") div.add_style("margin-left: 10px") titles = [ Common.get_display_title(x.replace("-", " ")) for x in aliases ] for alias, title in zip(aliases, titles): link_div = SpanWdg() div.add(link_div) link_div.add_color("background", "background") link_div.add(title) link_div.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.help.set_top(); spt.help.load_alias("%s"); ''' % alias }) link_div.add_class("spt_link") link_div.add_class("hand") return div
def filter_line_handler(my, path, line): '''NOT used now''' return line # this is only called if the project code is different from the # template code file_name = os.path.basename(path) if file_name in ['sthpw_project.spt']: # change codes to project code if line.startswith('''insert.set_value('code','''): line = '''insert.set_value('code', """%s""")\n''' % my.project_code elif line.startswith('''insert.set_value('title','''): title = Common.get_display_title(my.project_code) line = '''insert.set_value('title', """%s""")\n''' % title elif line.startswith('''insert.set_value('is_template','''): if my.is_template: line = '''insert.set_value('is_template', """true""")\n''' else: line = '''insert.set_value('is_template', """false""")\n''' elif file_name in ['sthpw_schema.spt']: if line.startswith('''insert.set_value('code','''): line = '''insert.set_value('code', """%s""")\n''' % my.project_code elif file_name in ['sthpw_pipeline.spt']: if line.startswith('''insert.set_value('project_code','''): line = '''insert.set_value('project_code', """%s""")\n''' % my.project_code return line
def get_title(self): if self.title: title = self.title title = title.replace(r'\n', '<br/>') if self.title.find("->") != -1: parts = self.title.split("->") title = parts[-1] else: title = self.name if self.name.find("->") != -1: parts = self.name.split("->") title = parts[-1] if not title: title = "" else: title = Common.get_display_title(title) title = _(title) from pyasm.web import DivWdg div = DivWdg() div.add_attr("title", title) div.add_style("margin-top", "6px") div.add(title) return div
def get_related_wdg(my, aliases): div = DivWdg() div.add("<b>Related links</b>:  ") div.add_style("margin-top: 5px") div.add_style("margin-bottom: 5px") div.add_style("margin-left: 10px") titles = [Common.get_display_title(x.replace("-"," ")) for x in aliases] for alias, title in zip(aliases, titles): link_div = SpanWdg() div.add(link_div) link_div.add_color("background", "background") link_div.add(title) link_div.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.help.set_top(); spt.help.load_alias("%s"); ''' % alias } ) link_div.add_class("spt_link") link_div.add_class("hand") return div
def get_title(self): if self.title: title = self.title title = title.replace(r'\n','<br/>') if self.title.find("->") != -1: parts = self.title.split("->") title = parts[-1] else: title = self.name if self.name.find("->") != -1: parts = self.name.split("->") title = parts[-1] if not title: title = "" else: title = Common.get_display_title(title) title = _(title) from pyasm.web import DivWdg div = DivWdg() div.add_attr("title", title) div.add_style("margin-top", "6px") div.add(title) return div
def set_all_tasks(my, sobject, process, status): tasks = Task.get_by_sobject(sobject, process=process) title = status.replace("-", " ") title = title.replace("_", " ") title = Common.get_display_title(title) for task in tasks: task.set_value("status", title) task.commit()
def get_data(my, sobject): values = [] labels = [] if not my.config: return values, labels for element in my.elements: if element.startswith("{") and element.endswith("}"): expr = element.strip("{}") value = Search.eval(expr, sobject, single=True) labels.append(element) else: options = my.config.get_display_options(element) attrs = my.config.get_element_attributes(element) label = attrs.get('title') if not label: label = Common.get_display_title(element) labels.append(label) widget = my.widgets.get(element) if not widget: widget = my.config.get_display_widget(element) my.widgets[element] = widget widget.set_sobject(sobject) try: value = widget.get_text_value() except: value = 0 if isinstance(value, basestring): if value.endswith("%"): value = float(value.replace("%", '')) else: value = 0 if not value: value = 0 #expression = options.get("expression") #if not expression: # value = 0 #else: # value = Search.eval(expression, sobject, single=True) if value > my.max_value: my.max_value = value values.append(value) return values, labels
def get_info_wdg(self, sobject): div = DivWdg() div.add_style("margin: 10px 20px 20px 20px") div.add_style("padding: 0px 20px") #div.add_color("background", "background", -3) #div.add_border() #div.add_color("color", "color3") #div.set_round_corners(5) div.add_style("height", "100%") div.add_style("position: relative") element_names = self.element_names config = self.config table = Table() table.add_style("height", "100%") div.add(table) for element_name in element_names: table.add_row() title = Common.get_display_title(element_name) td = table.add_cell("%s: " % title) td.add_style("width: 200px") td.add_style("padding: 5px") element = config.get_display_widget(element_name) if self.first: try: element.handle_layout_behaviors(self.layout_wdg) except Exception as e: print "e :", e pass element.set_sobject(sobject) element.preprocess() td = table.add_cell(element) td.add_style("padding: 5px") #value = sobject.get_value(element_name, no_exception=True) or "N/A" #table.add_cell(value) show_notes = self.kwargs.get("show_notes") if show_notes in [True, 'true']: div.add("<br/>") from tactic.ui.widget import DiscussionWdg search_key = sobject.get_search_key() notes_wdg = DiscussionWdg(search_key=search_key) notes_wdg.set_sobject(sobject) div.add(notes_wdg) return div
def configure_category(my, title, category, options, options_type = {}): div = DivWdg() title_wdg = DivWdg() div.add(title_wdg) #from tactic.ui.widget.swap_display_wdg import SwapDisplayWdg #swap = SwapDisplayWdg() #div.add(swap) title_wdg.add("<b>%s</b>" % title) table = Table() div.add(table) #table.add_color("color", "color") table.add_style("color: #000") table.add_style("margin: 20px") for option in options: table.add_row() display_title = Common.get_display_title(option) td = table.add_cell("%s: " % display_title) td.add_style("width: 150px") option_type = options_type.get(option) validation_scheme = "" #add selectWdg for those options whose type is bool if option_type == 'bool': text = SelectWdg(name="%s/%s" % (category, option)) text.set_option('values','true|false') text.set_option('empty','true') text.add_style("margin-left: 0px") elif option.endswith('password'): text = PasswordInputWdg(name="%s/%s" % (category, option)) # dealing with options whose type is number else: if option_type == 'number': validation_scheme = 'INTEGER' else: validation_scheme = "" text = TextInputWdg(name="%s/%s" % (category, option), validation_scheme=validation_scheme, read_only="false") value = Config.get_value(category, option) if value: text.set_value(value) table.add_cell(text) return div
def configure_category(my, title, category, options, options_type={}): div = DivWdg() title_wdg = DivWdg() div.add(title_wdg) #from tactic.ui.widget.swap_display_wdg import SwapDisplayWdg #swap = SwapDisplayWdg() #div.add(swap) title_wdg.add("<b>%s</b>" % title) table = Table() div.add(table) #table.add_color("color", "color") table.add_style("color: #000") table.add_style("margin: 20px") for option in options: table.add_row() display_title = Common.get_display_title(option) td = table.add_cell("%s: " % display_title) td.add_style("width: 150px") option_type = options_type.get(option) validation_scheme = "" #add selectWdg for those options whose type is bool if option_type == 'bool': text = SelectWdg(name="%s/%s" % (category, option)) text.set_option('values', 'true|false') text.set_option('empty', 'true') text.add_style("margin-left: 0px") elif option.endswith('password'): text = PasswordInputWdg(name="%s/%s" % (category, option)) # dealing with options whose type is number else: if option_type == 'number': validation_scheme = 'INTEGER' else: validation_scheme = "" text = TextInputWdg(name="%s/%s" % (category, option), validation_scheme=validation_scheme, read_only="false") value = Config.get_value(category, option) if value: text.set_value(value) table.add_cell(text) return div
def get_info_wdg(my, sobject): div = DivWdg() div.add_style("margin: 10px 20px 20px 20px") div.add_style("padding: 20px") div.add_color("background", "background", -3) div.add_border() div.add_color("color", "color3") div.set_round_corners(5) div.add_style("height", "100%") div.add_style("position: relative") element_names = my.kwargs.get("element_names") if not element_names: element_names = [ "code", "name", "description", ] else: element_names = element_names.split(",") view = "table" from pyasm.widget import WidgetConfigView search_type = sobject.get_search_type() config = WidgetConfigView.get_by_search_type(search_type, view) table = Table() table.add_style("height", "100%") div.add(table) for element_name in element_names: table.add_row() title = Common.get_display_title(element_name) td = table.add_cell("%s: " % title) td.add_style("width: 200px") td.add_style("padding: 5px") element = config.get_display_widget(element_name) element.set_sobject(sobject) element.preprocess() td = table.add_cell(element) td.add_style("padding: 5px") #value = sobject.get_value(element_name, no_exception=True) or "N/A" #table.add_cell(value) div.add("<br/>") from tactic.ui.widget import DiscussionWdg search_key = sobject.get_search_key() notes_wdg = DiscussionWdg(search_key=search_key) notes_wdg.set_sobject(sobject) div.add(notes_wdg) return div
def get_info_wdg(my, sobject): div = DivWdg() div.add_style("margin: 10px 20px 20px 20px") div.add_style("padding: 20px") div.add_color("background", "background", -3) div.add_border() div.add_color("color", "color3") div.set_round_corners(5) div.add_style("height", "100%") div.add_style("position: relative") element_names = my.kwargs.get("element_names") if not element_names: element_names = ["code","name","description",] else: element_names = element_names.split(",") view = "table" from pyasm.widget import WidgetConfigView search_type = sobject.get_search_type() config = WidgetConfigView.get_by_search_type(search_type, view) table = Table() table.add_style("height", "100%") div.add(table) for element_name in element_names: table.add_row() title = Common.get_display_title(element_name) td = table.add_cell("%s: " % title) td.add_style("width: 200px") td.add_style("padding: 5px") element = config.get_display_widget(element_name) element.set_sobject(sobject) element.preprocess() td = table.add_cell(element) td.add_style("padding: 5px") #value = sobject.get_value(element_name, no_exception=True) or "N/A" #table.add_cell(value) div.add("<br/>") from tactic.ui.widget import DiscussionWdg search_key = sobject.get_search_key() notes_wdg = DiscussionWdg(search_key=search_key) notes_wdg.set_sobject(sobject) div.add(notes_wdg) return div
def get_title(my): '''Returns a widget containing the title to be displayed for this column''' if my.title: title = my.title return title title = my.name if not title: title = "" return title title = Common.get_display_title(title) return title
def _get_title(self, config, element_name): attributes = config.get_element_attributes(element_name) title = attributes.get("title") if not title: title = Common.get_display_title(element_name) if '.' in title: parts = title.split('.', 1) title = parts[1] if not title or title == ' ': title = "(%s)" % element_name return title
def _get_title(my, config, element_name): attributes = config.get_element_attributes(element_name) title = attributes.get("title") if not title: title = Common.get_display_title(element_name) if '.' in title: parts = title.split('.', 1) title = parts[1] if not title or title == ' ': title = "(%s)" % element_name return title
def register(my, name, db_resource, tables=None): db_name = db_resource.get_database() project_code = "db_resource/%s" % db_name # create a virtual project project = SearchType.create("sthpw/project") # FIXME: what is this conflicts with an existing project project.set_value("code", project_code) project.set_value("db_resource", db_resource) # put this sobject into the cache from pyasm.biz import Project key = "sthpw/project|%s" % project_code Project.cache_sobject(key, project) if tables == None: # introspect and resister all of the tables sql = DbContainer.get(db_resource) table_info = sql.get_table_info() if table_info.get("spt_search_type"): print "has search_type" tables = table_info.keys() for table in tables: # FIXME: how is this created search_type = "table/%s?project=%s" % (table, db_name) #search_type_obj = SearchType.create("config/search_type") search_type_obj = SearchType.create("sthpw/search_type") search_type_obj.set_value("search_type", "table/%s" % table) search_type_obj.set_value("title", Common.get_display_title(table) ) search_type_obj.set_value("table_name", table) search_type_obj.set_value("database", db_name) SearchType.set_virtual(search_type, search_type_obj) my.db_resources[name] = db_resource
def get_custom_menu(my): menu_items = [] for tool in my.custom_tools: view = tool.get_value("view") title = tool.get_value("title") if not title: title = Common.get_display_title(view) menu_item = { "type": "action", "label": title, "bvr_cb": { 'title': title, 'view': view, 'cbjs_action': ''' var activator = spt.smenu.get_activator(bvr); var layout = activator.getParent(".spt_layout"); var selected = spt.table.get_selected_search_keys(); var kwargs = { view: bvr.view, search_keys: selected } var class_name = 'tactic.ui.panel.CustomLayoutWdg'; try { spt.panel.load_popup(bvr.title, class_name, kwargs); } catch(e) { spt.alert(spt.exception.handler(e)); } ''' } } menu_items.append(menu_item) return { 'menu_tag_suffix': 'CUSTOM', 'width': 210, 'opt_spec_list': menu_items }
def handle_headers(my, table): # this comes from refresh widths = my.kwargs.get("column_widths") # Add the headers tr = table.add_row() tr.add_class("spt_table_header_row") for i, widget in enumerate(my.widgets): widget_name = widget.get_name() th = table.add_header() th.add_style("text-align: left") th.add_attr("spt_element_name", widget_name) header_div = DivWdg() th.add(header_div) th.add_style("padding: 3px") th.add_gradient("background", "background", -5, -10) th.add_border() if my.mode == 'widget': value = widget.get_title() else: element = widget_name value = Common.get_display_title(element) header_div.add(value) if widths and len(widths) > i: th.add_style("width", widths[i]) width_set = True width = widths[i] else: # get width from definition width = my.attributes[i].get("width") if width: th.add_style("width", width) width_set = True if width: th.add_style("min-width", width) else: th.add_style("overflow","hidden") widget.handle_th(th, i)
def register(my, name, db_resource, tables=None): db_name = db_resource.get_database() project_code = "db_resource/%s" % db_name # create a virtual project project = SearchType.create("sthpw/project") # FIXME: what is this conflicts with an existing project project.set_value("code", project_code) project.set_value("db_resource", db_resource) # put this sobject into the cache from pyasm.biz import Project key = "sthpw/project|%s" % project_code Project.cache_sobject(key, project) if tables == None: # introspect and resister all of the tables sql = DbContainer.get(db_resource) table_info = sql.get_table_info() if table_info.get("spt_search_type"): print "has search_type" tables = table_info.keys() for table in tables: # FIXME: how is this created search_type = "table/%s?project=%s" % (table, db_name) #search_type_obj = SearchType.create("config/search_type") search_type_obj = SearchType.create("sthpw/search_type") search_type_obj.set_value("search_type", "table/%s" % table) search_type_obj.set_value("title", Common.get_display_title(table)) search_type_obj.set_value("table_name", table) search_type_obj.set_value("database", db_name) SearchType.set_virtual(search_type, search_type_obj) my.db_resources[name] = db_resource
def get_title(my): if my.title: title = my.title title = title.replace(r'\n','<br/>') else: title = my.name if not title: title = "" else: title = Common.get_display_title(title) from pyasm.web import DivWdg div = DivWdg() div.add_attr("title", title) div.add(title) return div # FIXME: not sure about autofit here? This should be a mode """
def get_title(my): if my.title: title = my.title title = title.replace(r'\n','<br/>') else: title = my.name if not title: title = "" else: title = Common.get_display_title(title) title = _(title) from pyasm.web import DivWdg div = DivWdg() div.add_attr("title", title) div.add(title) return div
def get_title(my): if my.title: title = my.title title = title.replace(r'\n', '<br/>') else: title = my.name if not title: title = "" else: title = Common.get_display_title(title) title = _(title) from pyasm.web import DivWdg div = DivWdg() div.add_attr("title", title) div.add(title) return div
def get_custom_menu(my): menu_items = [] for tool in my.custom_tools: view = tool.get_value("view") title = tool.get_value("title") if not title: title = Common.get_display_title(view) menu_item = { "type": "action", "label": title, "bvr_cb": { "title": title, "view": view, "cbjs_action": """ var activator = spt.smenu.get_activator(bvr); var layout = activator.getParent(".spt_layout"); var selected = spt.table.get_selected_search_keys(); var kwargs = { view: bvr.view, search_keys: selected } var class_name = 'tactic.ui.panel.CustomLayoutWdg'; try { spt.panel.load_popup(bvr.title, class_name, kwargs); } catch(e) { spt.alert(spt.exception.handler(e)); } """, }, } menu_items.append(menu_item) return {"menu_tag_suffix": "CUSTOM", "width": 210, "opt_spec_list": menu_items}
def configure_category(my, title, category, options): div = DivWdg() title_wdg = DivWdg() div.add(title_wdg) #from tactic.ui.widget.swap_display_wdg import SwapDisplayWdg #swap = SwapDisplayWdg() #div.add(swap) title_wdg.add("<b>%s</b>" % title) table = Table() div.add(table) #table.add_color("color", "color") table.add_style("color: #000") table.add_style("margin: 20px") for option in options: table.add_row() display_title = Common.get_display_title(option) td = table.add_cell("%s: " % display_title) td.add_style("width: 150px") if option.endswith('password'): text = PasswordInputWdg(name="%s/%s" % (category, option)) else: text = TextInputWdg(name="%s/%s" % (category, option)) value = Config.get_value(category, option) if value: text.set_value(value) table.add_cell(text) return div
def get_import_wdg(my): div = DivWdg() if my.data: div.add("<br/>" * 2) div.add("The following TACTIC share was found: ") div.add("<br/>" * 2) data_input = TextAreaWdg("data") data_input.add_style("display: none") div.add(data_input) #print "xxxx: ", my.data data_str = jsondumps(my.data) #data_str = data_str.replace('"', "'") print "data: ", data_str data_input.set_value(data_str) table = Table() div.add(table) table.set_max_width() table.add_style("margin-left: 20px") table.add_style("margin-right: 20px") for name, value in my.data.items(): name = Common.get_display_title(name) table.add_row() table.add_cell(name) table.add_cell(value) div.add("<br/>" * 2) div.add(my.get_versions_wdg()) div.add("<br/>" * 2) # check to see if the project exists project_code = my.data.get("project_code") project_code = my.data.get("projects") project = Project.get_by_code(project_code) #if project: if False: msg_div = DivWdg() div.add(msg_div) msg_div.add_style("padding: 20px") msg_div.add_color("background", "background3") msg_div.add_color("color", "color") msg_div.add_border() icon = IconWdg("WARNING", IconWdg.WARNING) msg_div.add(icon) icon.add_style("float: left") msg_div.add( "The project with code [%s] already exists. You must remove the installed project before trying to import this one." % project_code) return div if my.data.get("is_encrypted") == "true": div.add( "The transactions in this share is encrypted. Please provide an encryption key to decrypt the transactions<br/><br/>" ) div.add("Encryption Key: ") text = TextWdg("encryption_key") div.add(text) div.add("<br/>" * 2) button = ActionButtonWdg(title="Import >>") button.add_style("float: right") div.add(button) div.add("<br/>" * 2) button.add_behavior({ 'type': 'click_up', 'project_code': project_code, 'cbjs_action': ''' spt.app_busy.show("Importing Project "+bvr.project_code+"..."); var top = bvr.src_el.getParent(".spt_sync_import_top"); var values = spt.api.Utility.get_input_values(top, null, false); var cmd = "tactic.ui.sync.SyncImportCmd"; var server = TacticServerStub.get(); server.execute_cmd(cmd, values, {}, {use_transaction: false}); spt.notify.show_message("Finished importing project"); spt.app_busy.hide(); document.location = '/tactic/'+bvr.project_code; ''' }) return div
def get_display(self): self.config_search_type = self.kwargs.get("config_search_type") if not self.config_search_type: self.config_search_type = "SideBarWdg" title = self.kwargs.get('title') config = self.kwargs.get('config') view = self.kwargs.get('view') width = self.kwargs.get('width') #sortable = self.kwargs.get('sortable') if not width: width = "175" self.prefix = self.kwargs.get("prefix") if not self.prefix: self.prefix = "side_bar" self.mode = self.kwargs.get("mode") if not self.mode: self.mode = 'view' self.default = self.kwargs.get('default') == 'True' div = DivWdg() div.add_class("spt_section_top") div.set_attr("SPT_ACCEPT_DROP", "manageSideBar") # create the top widgets label = SpanWdg() label.add(title) label.add_style("font-size: 1.1em") section_div = LabeledHidableWdg(label=label) div.add(section_div) section_div.set_attr('spt_class_name', Common.get_full_class_name(self)) for name, value in self.kwargs.items(): if name == "config": continue section_div.set_attr("spt_%s" % name, value) bgcolor = label.get_color("background3") project_div = RoundedCornerDivWdg(hex_color_code=bgcolor, corner_size="10") project_div.set_dimensions(width_str='%spx' % width, content_height_str='100px') content_div = project_div.get_content_wdg() #project_div = DivWdg() #content_div = project_div section_div.add(project_div) content_div.add_class("spt_side_bar_content") content_div.add_attr("spt_view", view) if type(view) in types.StringTypes: view = [view] view_margin_top = '4px' web = WebContainer.get_web() for viewx in view: config = self.get_config(self.config_search_type, viewx, default=self.default) if not config: continue # make up a title title = DivWdg() title.add_gradient("background", "side_bar_title", 0, -15, default="background") title.add_color("color", "side_bar_title_color", default="color") title.add_styles( "margin-top: %s; margin-bottom: 3px; vertical-align: middle" % view_margin_top) if not web.is_IE(): title.add_styles("margin-left: -5px; margin-right: -5px;") title.add_looks("navmenu_header") title.add_style("height: 18px") title.add_style("padding-top: 2px") """ title = DivWdg() title.add_styles( "margin-top: %s; margin-bottom: 3px; vertical-align: middle" % view_margin_top ) if not web.is_IE(): title.add_styles( "margin-left: -10px; margin-right: -10px;") title.add_looks( "navmenu_header" ) """ # FIXME: not sure if this logic should be here. It basically # makes special titles for certain view names view_attrs = config.get_view_attributes() title_str = view_attrs.get("title") if not title_str: if viewx.startswith("self_view_"): title_str = "My Views" else: title_str = viewx title_str = Common.get_display_title(title_str) title_label = SpanWdg() title_label.add_styles("margin-left: 6px; padding-bottom: 2px;") title_label.add_looks("fnt_title_5 fnt_bold") title_label.add(title_str) title.add(title_label) content_div.add(title) info = {'counter': 10, 'view': viewx} self.generate_section(config, content_div, info) error_list = Container.get_seq(self.ERR_MSG) if error_list: span = SpanWdg() span.add_style('background', 'red') span.add('<br/>'.join(error_list)) content_div.add(span) Container.clear_seq(self.ERR_MSG) self.add_dummy(config, content_div) return div
def get_display(my): top = DivWdg() top.add_border() top.add_style("padding: 10px") top.add_color("color", "color") top.add_gradient("background", "background", 0, -5) #top.add_style("height: 550px") top.add_class("spt_reports_top") my.set_as_panel(top) inner = DivWdg() top.add(inner) title = DivWdg() title.add("Reports") title.add_style("font-size: 18px") title.add_style("font-weight: bold") title.add_style("text-align: center") title.add_style("padding: 10px") title.add_style("margin: -10px -10px 0px -10px") inner.add(title) title.add_gradient("background", "background3", 5, -10) from tactic.ui.widget import TitleWdg subtitle = TitleWdg(name_of_title='List of Built in Reports',help_alias='main') inner.add(subtitle) inner.add("<br/>") button_div = DivWdg() inner.add(button_div) button_div.add_class("spt_buttons_top") button_div.add_style("margin-top: -5px") button_div.add_style("margin-bottom: 30px") button_div.add_border() button_div.add_style("margin-top: -15px") button_div.add_style("margin-bottom: 0px") button_div.add_style("width: 100%") button_div.add_style("height: 33px") button_div.add_color("background", "background2") button_div.add_style("margin-left: auto") button_div.add_style("margin-right: auto") button = SingleButtonWdg(title="Collapse", icon=IconWdg.HOME) button_div.add(button) button.add_style("float: left") button.add_style("left: 5px") button.add_style("top: 5px") # FIXME: get home for the user #home = 'tactic.ui.startup.ContentCreatorWdg' home = 'tactic.ui.startup.MainWdg' button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.tab.set_main_body_tab(); var class_name = 'tactic.ui.startup.MainWdg'; var kwargs = { help_alias: 'main' }; spt.tab.add_new("_startup", "Startup", class_name, kwargs); ''' } ) """ button = SingleButtonWdg(title="Collapse", icon=IconWdg.ARROW_UP) button_div.add(button) button.add_class("spt_collapse") inner.add(button_div) button.add_style("float: left") button.add_style("left: 5px") button.add_style("top: 5px") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_reports_top"); var element = top.getElement(".spt_reports_list"); var buttons = bvr.src_el.getParent(".spt_buttons_top"); expand = buttons.getElement(".spt_expand"); new Fx.Tween(element).start('margin-top', "-400px"); expand.setStyle("display", ""); bvr.src_el.setStyle("display", "none"); ''' } ) button = SingleButtonWdg(title="Expand", icon=IconWdg.ARROW_DOWN) button.add_style("display: none") button.add_class("spt_expand") button_div.add(button) button.add_style("left: 5px") button.add_style("top: 5px") inner.add(button_div) button.add_style("float: left") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_reports_top"); var element = top.getElement(".spt_reports_list"); var buttons = bvr.src_el.getParent(".spt_buttons_top"); collapse = buttons.getElement(".spt_collapse"); new Fx.Tween(element).start('margin-top', "0px"); collapse.setStyle("display", ""); bvr.src_el.setStyle("display", "none"); ''' } ) """ reports = [] # read the config file from pyasm.widget import WidgetConfig tmp_path = __file__ dir_name = os.path.dirname(tmp_path) file_path="%s/../config/reports-conf.xml" % (dir_name) config = WidgetConfig.get(file_path=file_path, view="definition") category = my.kwargs.get('category') # get all of the configs from the database if not category or category in ["custom_reports", "custom_charts"]: search = Search("config/widget_config") search.add_op("begin") if category == "custom_reports": search.add_filter("widget_type", "report") elif category == "custom_charts": search.add_filter("widget_type", "chart") elif not category: search.add_filters("widget_type", ["chart","report"]) search.add_op("or") db_configs = search.get_sobjects() else: db_configs = [] element_names = my.kwargs.get("element_names") if element_names is None: element_names = config.get_element_names() project = Project.get() for element_name in element_names: key = {'project': project.get_code(), 'element': element_name} key2 = {'project': project.get_code(), 'element': '*'} key3 = {'element': element_name} key4 = {'element': '*'} keys = [key, key2, key3, key4] if not top.check_access("link", keys, "view", default="deny"): continue attrs = config.get_element_attributes(element_name) report_data = {} kwargs = config.get_display_options(element_name) class_name = kwargs.get('class_name') # the straight xml definition contains the sidebar class_name # with LinkWdg ... we shouldn't use this, so build the # element from scratch #xml = config.get_element_xml(element_name) from pyasm.search import WidgetDbConfig xml = WidgetDbConfig.build_xml_definition(class_name, kwargs) report_data['class_name'] = class_name report_data['kwargs'] = kwargs report_data['title'] = attrs.get("title") report_data['description'] = attrs.get("description") report_data['image'] = attrs.get("image") report_data['xml'] = xml reports.append(report_data) for db_config in db_configs: element_name = db_config.get_value("view") key = {'project': project.get_code(), 'element': element_name} key2 = {'project': project.get_code(), 'element': '*'} key3 = {'element': element_name} key4 = {'element': '*'} keys = [key, key2, key3, key4] if not top.check_access("link", keys, "view", default="deny"): continue report_data = {} view = db_config.get_value("view") kwargs = { 'view': view } parts = view.split(".") title = Common.get_display_title(parts[-1]) xml = db_config.get_value("config") report_data['class_name'] = "tactic.ui.panel.CustomLayoutWdg" report_data['kwargs'] = kwargs report_data['title'] = title report_data['description'] = title report_data['image'] = None report_data['xml'] = xml report_data['widget_type'] = db_config.get_value("widget_type") if report_data['widget_type'] == 'report': report_data['category'] = "custom_reports" elif report_data['widget_type'] == 'chart': report_data['category'] = "custom_charts" reports.append(report_data) """ report_data = { 'title': 'Tasks Completed This Week', 'class_name': 'tactic.ui.panel.ViewPanelWdg', 'kwargs': { 'search_type': 'sthpw/task', 'view': 'table' }, } reports.append(report_data) """ if category == 'list_item_reports' or not category: search_types = Project.get().get_search_types() for search_type in search_types: base_key = search_type.get_base_key() key = {'project': project.get_code(), 'code': base_key} key2 = {'project': project.get_code(), 'code': '*'} key3 = {'code': base_key} key4 = {'code': '*'} keys = [key, key2, key3, key4] if not top.check_access("search_type", keys, "view", default="deny"): continue if not SearchType.column_exists(base_key, "pipeline_code"): continue thumb_div = DivWdg() image = thumb_div thumb_div.add_border() thumb_div.set_box_shadow("1px 1px 1px 1px") thumb_div.add_style("width: 60px") thumb = ThumbWdg() thumb_div.add(thumb) thumb.set_sobject(search_type) thumb.set_icon_size(60) report_data = { 'title': '%s Workflow Status' % search_type.get_title(), 'description': 'Number of items in each process', 'class_name': 'tactic.ui.report.stype_report_wdg.STypeReportWdg', 'kwargs': { 'search_type': base_key }, 'image': thumb_div } reports.append(report_data) report_data = { 'title': '%s Labor Cost Report' % search_type.get_title(), 'description': 'Labor Cost Breakdown for each Item', 'class_name': 'tactic.ui.panel.ViewPanelWdg', 'kwargs': { 'search_type': search_type.get_code(), 'view': "table", 'show_header': False, 'mode': 'simple', 'element_names': "preview,code,title,cost_breakdown,bid_hours,bid_cost,actual_hours,actual_cost,overbudget,variance" }, 'image': IconWdg("", IconWdg.REPORT_03) } reports.append(report_data) table2 = Table() inner.add(table2) table2.add_style("width: 100%") categories_div = DivWdg() td = table2.add_cell(categories_div) td.add_style("vertical-align: top") td.add_style("width: 200px") td.add_color("background", "background3") td.add_border() #categories_div.add_style("margin: -1px 0px 0px -1px") categories_div.add_style("padding-top: 10px") #categories_div.add_style("float: left") categories_div.add_color("color", "color3") categories = config.get_all_views() categories.insert(-1, "list_item_reports") categories.insert(-1, "custom_charts") categories.insert(-1, "custom_reports") table_div = DivWdg() td = table2.add_cell(table_div) td.add_style("vertical-align: top") table_div.add_class("spt_reports_list") table_div.add_border() table_div.add_color("background", "background", -5) table_div.add_style("min-height: 500px") for i, category in enumerate(categories): if i == len(categories) - 1: categories_div.add("<hr/>") config.set_view(category) element_names = config.get_element_names() if category == "definition": title = "All Reports" else: title = Common.get_display_title(category) category_div = DivWdg() categories_div.add(category_div) category_div.add(title) category_div.add_style("padding: 5px") category_div.add_class("hand") category_div.add_behavior( { 'type': 'click_up', 'category': category, 'element_names': element_names, 'class_name': Common.get_full_class_name(my), 'cbjs_action': ''' var kwargs = { is_refresh: true, category: bvr.category, element_names: bvr.element_names } //spt.panel.refresh(top, kwargs); var top = bvr.src_el.getParent(".spt_reports_top"); spt.panel.load(top, bvr.class_name, kwargs); ''' } ) bgcolor = category_div.get_color("background3", -10) category_div.add_behavior( { 'type': 'mouseover', 'bgcolor': bgcolor, 'cbjs_action': ''' bvr.src_el.setStyle("background", bvr.bgcolor); ''' } ) category_div.add_behavior( { 'type': 'mouseout', 'bgcolor': bgcolor, 'cbjs_action': ''' bvr.src_el.setStyle("background", ""); ''' } ) # create a bunch of panels table = Table() table_div.add(table) table.add_color("color", "color") table.add_style("margin-top: 20px") table.center() table_div.add_style("margin: -3px -3px -1px -2px") if not reports: tr = table.add_row() td = table.add_cell() td.add("There are no reports defined.") td.add_style("padding: 50px") if my.kwargs.get("is_refresh") in ['true', True]: return inner else: return top for i, report in enumerate(reports): #if i == 0 or i%4 == 0: if i%3 == 0: tr = table.add_row() td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = report #description = '''The schema is used to layout the basic components of your project. Each component represents a list of items that you use in your business everyday.''' description = report.get("title") # Each node will contain a list of "items" and will be stored as a table in the database.''' class_name = report.get("class_name") kwargs = report.get("kwargs") title = report.get("title") description = report.get("description") widget_type = report.get("widget_type") image = report.get("image") icon = report.get("icon") xml = report.get("xml") if image: div = DivWdg() if isinstance(image, basestring): image = image.upper() image = eval("IconWdg('', IconWdg.%s)" % image) div.add_style("margin-left: 15px") div.add_style("margin-top: 5px") else: image = image div.add(image) image = div elif icon: icon = icon.upper() image = eval("IconWdg('', IconWdg.%s)" % icon) else: div = DivWdg() """ import random num = random.randint(0,3) if num == 1: image = IconWdg("Bar Chart", IconWdg.GRAPH_BAR_01) elif num == 2: image = IconWdg("Bar Chart", IconWdg.GRAPH_LINE_01) else: image = IconWdg("Bar Chart", IconWdg.GRAPH_BAR_02) """ if widget_type == "chart": image = IconWdg("Chart", IconWdg.GRAPH_BAR_02) else: image = IconWdg("No Image", IconWdg.WARNING) div.add_style("margin-left: 15px") div.add_style("margin-top: 5px") div.add(image) image = div behavior = { 'type': 'click_up', 'title': title, 'class_name': class_name, 'kwargs': kwargs, 'cbjs_action': ''' spt.tab.set_main_body_tab(); //var top = bvr.src_el.getParent(".spt_reports_top"); //spt.tab.set_tab_top(top); spt.tab.add_new(bvr.title, bvr.title, bvr.class_name, bvr.kwargs); ''' } schema_wdg = my.get_section_wdg(title, description, image, behavior) schema_wdg.add_behavior( { 'type': 'load', 'title': title, 'class_name': class_name, 'xml': xml, 'kwargs': kwargs, 'cbjs_action': ''' var report_top = bvr.src_el; report_top.kwargs = bvr.kwargs; report_top.class_name = bvr.class_name; report_top.element_name = bvr.title; report_top.xml = bvr.xml; ''' } ) td.add(schema_wdg) inner.add("<br/>") #from tactic.ui.container import TabWdg #tab = TabWdg(show_add=False) #inner.add(tab) if my.kwargs.get("is_refresh") in ['true', True]: return inner else: return top
def get_display(self): top = self.top scan_path = "/tmp/scan" if not os.path.exists(scan_path): top.add("No results in current scan session") return top base_dir = "/home/apache" total_count = 0 mode = 'not' if mode == 'scan': # find all the files in the scanned data f = open(scan_path) data = jsonloads( f.read() ) f.close() elif mode == 'not': # find all of the files not in the scanned data f = open(scan_path) scan_data = jsonloads( f.read() ) f.close() data = {} count = 0 limit = 5000 for root, dirs, files in os.walk(base_dir): for file in files: total_count += 1 path = "%s/%s" % (root, file) if scan_data.get(path) == None: continue count +=1 if count > limit: break (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(path) data[path] = {"size": size} if count > limit: break elif mode == 'bad': data = {} count = 0 limit = 5000 for root, dirs, files in os.walk(base_dir): for file in files: path = "%s/%s" % (root, file) if not self.check_irregular(path): continue count +=1 if count > limit: break (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(path) data[path] = {"size": size} if count > limit: break elif mode == 'png': data = {} count = 0 limit = 5000 for root, dirs, files in os.walk(base_dir): for file in files: path = "%s/%s" % (root, file) if not path.endswith(".png"): continue count +=1 if count > limit: break (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(path) data[path] = {"size": size} if count > limit: break elif mode == 'custom': data = {} count = 0 limit = 5000 # What does this look like??? handler = Hander() for root, dirs, files in os.walk(base_dir): for file in files: path = "%s/%s" % (root, file) if not handler.validate(): continue count +=1 if count > limit: break (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(path) data[path] = {"size": size} if count > limit: break paths = data.keys() paths.sort() sobjects = [] for path in paths: sobject = SearchType.create("sthpw/virtual") basename = os.path.basename(path) dirname = os.path.dirname(path) reldir = dirname.replace("%s" % base_dir, "") basename = os.path.basename(path) dirname = os.path.dirname(path) reldir = dirname.replace("%s" % base_dir, "") if not reldir: reldir = ' ' else: reldir.lstrip("/") if not basename: basename = ' ' sobject.set_value("folder", reldir) sobject.set_value("file_name", basename) sobjects.append(sobject) info = data.get(path) if info: sobject.set_value("size", info.get("size")) from tactic.ui.panel import TableLayoutWdg element_names = ['folder','file_name', 'size'] #element_names.extend( list(tags_keys) ) #show_metadata = False #if not show_metadata: # element_names.remove('metadata') #config_xml = self.get_config_xml(list(tags_keys)) #layout = TableLayoutWdg(search_type='sthpw/virtual', view='report', element_names=element_names, mode='simple') #layout.set_sobjects(sobjects) #top.add(layout) top.add("Matched %s items of %s<br/>" % (len(sobjects), total_count) ) table = Table() table.add_color("color", "color") top.add(table) table.add_row() for element_name in element_names: title = Common.get_display_title(element_name) td = table.add_cell("<b>%s</b>" % title) td.add_border() td.add_color("color", "color", +5) td.add_gradient('background', 'background', -20) td.add_style("height: 20px") td.add_style("padding: 3px") for row, sobject in enumerate(sobjects): tr = table.add_row() if row % 2: background = tr.add_color("background", "background") else: background = tr.add_color("background", "background", -2) tr.add_attr("spt_background", background) for element_name in element_names: td = table.add_cell(sobject.get_value(element_name)) td.add_border() return top
def get_default_wdg(cls, aliases=[]): div = DivWdg() div.set_unique_id() div.add_style("padding: 5px") if aliases: div.add("<b>Related links</b>:<br/><br/>") titles = [Common.get_display_title(x.replace("-"," ")) for x in aliases] for alias, title in zip(aliases, titles): link_div = DivWdg() div.add(link_div) link_div.add_color("background", "background") link_div.add(title) link_div.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.help.set_top(); spt.help.load_alias("%s"); ''' % alias } ) link_div.add_class("spt_link") link_div.add_class("hand") div.add("<br/><br/>") div.add("<b>Additional useful links</b>:<br/><br/>") aliases = ['setup', 'end_user', 'developer', 'sys_admin'] titles = ['Project Setup Documentation', 'End User Documentation', 'Developer Documentation', 'System Administrator Documentation'] for alias, title in zip(aliases, titles): link_div = DivWdg() div.add(link_div) link_div.add_color("background", "background") link_div.add(title) link_div.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.help.set_top(); spt.help.load_alias("%s"); ''' % alias } ) link_div.add_class("spt_link") link_div.add_class("hand") div.add("<br/>") link_div = DivWdg() div.add(link_div) link_div.add("TACTIC Documentation (PDF)") link_div.add_color("background", "background") link_div.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' window.open("/doc/", "TACTIC Docs"); ''' } ) link_div.add_class("spt_link") link_div.add_class("hand") link_div = DivWdg() div.add(link_div) link_div.add_color("background", "background") link_div.add("TACTIC Community Site") link_div.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' window.open("http://community.southpawtech.com", "TACTIC Community Site"); ''' } ) link_div.add_class("spt_link") link_div.add_class("hand") return div
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 = DivWdg() top.add_class("spt_wizard_top") my.height = my.kwargs.get("height") width = my.kwargs.get("width") if not width: width = "" my.width = width inner = DivWdg() top.add(inner) inner.add_style("width: %s" % width) title = my.kwargs.get("title") if not title: title = "none" if title != "none": title_wdg = DivWdg() inner.add(title_wdg) title_wdg.add(title) title_wdg.add_style("font-size: 16px") title_wdg.add_style("font-weight: bold") inner.add("<br/>") my.titles = my.kwargs.get("titles") if isinstance(my.titles, basestring): my.titles = my.titles.split("|") if not my.titles: my.titles = [] views = my.kwargs.get("views") if views: from tactic.ui.panel import CustomLayoutWdg if isinstance(views, basestring): views = views.split("|") for i, view in enumerate(views): if i < len(my.titles): title = my.titles[i] else: title = widget.get_name() title = title.replace(".", " ") title = Common.get_display_title(title) widget = CustomLayoutWdg(view=view) my.add(widget, title) header_wdg = my.get_header_wdg() inner.add(header_wdg) #header_wdg.add_color("background", "background", -5) header_wdg.add_class("spt_popup_header") inner.add("<br/>") inner.add("<hr/>") pages_div = DivWdg() pages_div.add_class("spt_popup_body") inner.add(pages_div) pages_div.add_style("overflow-y: auto") for i, widget in enumerate(my.widgets): page_div = DivWdg() page_div.add_class("spt_wizard_page") pages_div.add(page_div) page_div.add_style("padding: 10px") page_div.add_style("min-height: 300px") if my.height: page_div.add_style("height: %s" % my.height) page_div.add_style("overflow-y: auto") if i != 0: page_div.add_style("display: none") else: page_div.add_class("spt_wizard_selected") page_div.add(widget) pages_div.add("<hr/>") bottom_wdg = my.get_bottom_wdg() bottom_wdg.add_class("spt_popup_footer") inner.add(bottom_wdg) return top
def filter_sobject_handler(my, sobject): search_type = sobject.get_base_search_type() if search_type == 'sthpw/project': project = Project.get_by_code(my.project_code) if project: sobject.set_value("id", project.get_id()) # change the code of the project sobject.set_value("code", my.project_code) title = Common.get_display_title(my.project_code) sobject.set_value("title", title) if my.is_template: sobject.set_value("is_template", True) else: sobject.set_value("is_template", False) elif search_type == 'sthpw/schema': sobject.set_value("code", my.project_code) elif search_type == 'sthpw/notification': sobject.set_value("project_code", my.project_code) sobject.set_value("code", "") elif search_type in ['sthpw/pipeline']: sobject.set_value("project_code", my.project_code) if my.template_project_code != my.project_code: # get the old code old_code = sobject.get_code() if old_code.startswith("%s/" % my.template_project_code): new_code = old_code.replace( "%s/" % my.template_project_code, "%s/" % my.project_code) else: new_code = "%s/%s" % (my.project_code, old_code) sobject.set_value("code", new_code) elif search_type in ['sthpw/login_group']: sobject.set_value("project_code", my.project_code) if my.template_project_code != my.project_code: # get the old login_group for column in ['login_group', 'code']: old_code = sobject.get_value(column) if old_code.startswith("%s/" % my.template_project_code): new_code = old_code.replace( "%s/" % my.template_project_code, "%s/" % my.project_code) else: new_code = "%s/%s" % (my.project_code, old_code) sobject.set_value(column, new_code) # go through the access rules and replace project access_rules = sobject.get_xml_value("access_rules") nodes = access_rules.get_nodes("rules/rule") for node in nodes: project_code = Xml.get_attribute(node, "project") if project_code and project_code != "*" and project_code == my.template_project_code: Xml.set_attribute(node, "project", my.project_code) sobject.set_value("access_rules", access_rules.to_string()) return sobject
def execute(self): project_code = self.kwargs.get('project_code') project_title = self.kwargs.get('project_title') project_type = self.kwargs.get('project_type') project_description = self.kwargs.get("description") if not project_type: project_type = "simple" is_template = self.kwargs.get('is_template') project_theme = self.kwargs.get('project_theme') use_default_side_bar = self.kwargs.get('use_default_side_bar') if use_default_side_bar in [False, 'false']: use_default_side_bar = False else: use_default_side_bar = True assert project_code assert project_type if project_type: # check to see if it exists search = Search("sthpw/project_type") search.add_filter("code", project_type) project_type_sobj = search.get_sobject() if not project_type_sobj: # just create a default one in this case if it is named # after the project code if not is_template and project_type == project_code: project_type = 'default' # create a new project type search = Search("sthpw/project_type") search.add_filter("code", project_type) project_type_sobj = search.get_sobject() if not project_type_sobj: project_type_sobj = SearchType.create("sthpw/project_type") project_type_sobj.set_value("code", project_type) project_type_sobj.set_value("type", "simple") project_type_sobj.commit() # set the current project to Admin Project.set_project("admin") # create a new project sobject project = SearchType.create("sthpw/project") project.set_value("code", project_code) project.set_value("title", project_title) project.set_value("type", project_type) if project_description: project.set_value("description", project_description) # set the update of the database to current (this is obsolete) #project.set_value("last_db_update", "now()") project.set_value("last_version_update", "2.5.0.v01") if is_template in ['true', True, 'True']: project.set_value("is_template", True) else: project.set_value("is_template", False) if project_type != "default": category = Common.get_display_title(project_type) project.set_value("category", category) project.commit() # if there is an image, check it in upload_path = self.kwargs.get("project_image_path") if upload_path: if not os.path.exists(upload_path): raise TacticException("Cannot find upload image for project [%s]" % upload_path) file_type = 'main' file_paths = [upload_path] file_types = [file_type] source_paths = [upload_path] from pyasm.biz import IconCreator if os.path.isfile(upload_path): icon_creator = IconCreator(upload_path) icon_creator.execute() web_path = icon_creator.get_web_path() icon_path = icon_creator.get_icon_path() if web_path: file_paths = [upload_path, web_path, icon_path] file_types = [file_type, 'web', 'icon'] from pyasm.checkin import FileCheckin checkin = FileCheckin(project, context='icon', file_paths=file_paths, file_types=file_types) checkin.execute() # find project's base_type base_type = project.get_base_type() if not base_type and project_type =='unittest': base_type = 'unittest' elif not base_type: base_type = 'simple' # get the database for this project db_resource = project.get_project_db_resource() database = db_resource.get_database_impl() #database = DatabaseImpl.get() database_type = database.get_database_type() if database_type == 'Oracle': raise TacticException("Creation of project is not supported. Please create manually") # creating project database print "Creating database '%s' ..." % project_code try: # create the datbase database.create_database(db_resource) except Exception as e: print str(e) print "WARNING: Error creating database [%s]" % project_code # import the appropriate schema with config first database.import_schema(db_resource, base_type) self.create_schema(project_code) # before we upgrade, we have to commit the transaction # This is because upgrade actually run as separate processes # so if not commit has been made, the tables from importing the # schema will not have existed yet DbContainer.commit_thread_sql() self.upgrade() # import the appropriate data database.import_default_data(db_resource, base_type) # import default links if use_default_side_bar: self.import_default_side_bar() # create specified stypes self.create_search_types() # create theme if project_theme: self.create_theme(project_theme) # set as main project is_main_project = self.kwargs.get("is_main_project") if is_main_project in [True,'true','on']: Config.set_value("install", "default_project", project_code) Config.save_config() Config.reload_config() # initiate the DbContainer DbContainer.get('sthpw') self.info['result'] = "Finished creating project [%s]."%project_code print "Done."
def get_display(my): top = DivWdg() top.add_border() top.add_style("padding: 10px") top.add_color("color", "color") top.add_color("background", "background") top.add_class("spt_reports_top") title = DivWdg() title.add("Dashboards") title.add_style("font-size: 18px") title.add_style("font-weight: bold") title.add_style("text-align: center") title.add_style("padding: 10px") title.add_style("margin: -10px -10px 10px -10px") title.add_gradient("background", "background3", 5, -10) top.add(title) from tactic.ui.widget import TitleWdg subtitle = TitleWdg(name_of_title='List of Dashboards', help_alias='project-startup-dashboards') top.add(subtitle) top.add("<br/>") dashboards = [] # read the config file from pyasm.widget import WidgetConfig tmp_path = __file__ dir_name = os.path.dirname(tmp_path) file_path = "%s/../config/dashboard-conf.xml" % (dir_name) config = WidgetConfig.get(file_path=file_path, view="definition") element_names = config.get_element_names() for element_name in element_names: attrs = config.get_element_attributes(element_name) dashboard_data = {} kwargs = config.get_display_options(element_name) class_name = kwargs.get('class_name') dashboard_data['class_name'] = class_name dashboard_data['kwargs'] = kwargs dashboard_data['title'] = attrs.get("title") dashboard_data['description'] = attrs.get("description") dashboard_data['image'] = attrs.get("image") dashboard_data['image'] = attrs.get("image") dashboards.append(dashboard_data) # get all of the configs from the database search = Search("config/widget_config") search.add_filter("widget_type", "dashboard") db_configs = search.get_sobjects() for db_config in db_configs: dashboard_data = {} view = db_config.get_value("view") kwargs = {'view': view} parts = view.split(".") title = Common.get_display_title(parts[-1]) xml = db_config.get_value("config") dashboard_data['class_name'] = "tactic.ui.panel.CustomLayoutWdg" dashboard_data['kwargs'] = kwargs dashboard_data['title'] = title dashboard_data['description'] = title dashboard_data['image'] = None dashboard_data['xml'] = xml dashboard_data['widget_type'] = db_config.get_value("widget_type") dashboards.append(dashboard_data) # create a bunch of panels table = Table() top.add(table) table.add_color("color", "color") table.add_style("margin-bottom: 20px") table.center() for i, dashboard in enumerate(dashboards): if i == 0 or i % 4 == 0: tr = table.add_row() td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = dashboard description = dashboard.get("title") # Each node will contain a list of "items" and will be stored as a table in the database.''' class_name = dashboard.get("class_name") kwargs = dashboard.get("kwargs") title = dashboard.get("title") description = dashboard.get("description") xml = dashboard.get("xml") or "" image = dashboard.get("image") icon = dashboard.get("icon") if image: div = DivWdg() if isinstance(image, basestring): image = image.upper() image = eval("IconWdg('', IconWdg.%s)" % image) div.add_style("margin-left: 15px") div.add_style("margin-top: 5px") else: image = image div.add(image) image = div elif icon: icon = icon.upper() image = eval("IconWdg('', IconWdg.%s)" % icon) else: div = DivWdg() #image = IconWdg("Bar Chart", IconWdg.WARNING) image = IconWdg("Bar Chart", IconWdg.DASHBOARD_02) div.add_style("margin-left: 15px") div.add_style("margin-top: 5px") div.add(image) image = div behavior = { 'type': 'click_up', 'title': title, 'class_name': class_name, 'kwargs': kwargs, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_reports_top"); spt.tab.set_main_body_tab(); //spt.tab.set_tab_top(top); var kwargs = {}; spt.tab.add_new(bvr.title, bvr.title, bvr.class_name, bvr.kwargs); ''' } schema_wdg = my.get_section_wdg(title, description, image, behavior) schema_wdg.add_behavior({ 'type': 'load', 'title': title, 'class_name': class_name, 'xml': xml, 'kwargs': kwargs, 'cbjs_action': ''' var report_top = bvr.src_el; report_top.kwargs = bvr.kwargs; report_top.class_name = bvr.class_name; report_top.element_name = bvr.title; report_top.xml = bvr.xml; ''' }) td.add(schema_wdg) #from tactic.ui.container import TabWdg #tab = TabWdg(show_add=False) #top.add(tab) return top
def get_display(self): top = self.top scan_path = "/tmp/scan" if not os.path.exists(scan_path): top.add("No results in current scan session") return top base_dir = "/home/apache" total_count = 0 mode = 'not' if mode == 'scan': # find all the files in the scanned data f = open(scan_path) data = jsonloads(f.read()) f.close() elif mode == 'not': # find all of the files not in the scanned data f = open(scan_path) scan_data = jsonloads(f.read()) f.close() data = {} count = 0 limit = 5000 for root, dirs, files in os.walk(base_dir): for file in files: total_count += 1 path = "%s/%s" % (root, file) if scan_data.get(path) == None: continue count += 1 if count > limit: break (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(path) data[path] = {"size": size} if count > limit: break elif mode == 'bad': data = {} count = 0 limit = 5000 for root, dirs, files in os.walk(base_dir): for file in files: path = "%s/%s" % (root, file) if not self.check_irregular(path): continue count += 1 if count > limit: break (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(path) data[path] = {"size": size} if count > limit: break elif mode == 'png': data = {} count = 0 limit = 5000 for root, dirs, files in os.walk(base_dir): for file in files: path = "%s/%s" % (root, file) if not path.endswith(".png"): continue count += 1 if count > limit: break (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(path) data[path] = {"size": size} if count > limit: break elif mode == 'custom': data = {} count = 0 limit = 5000 # What does this look like??? handler = Hander() for root, dirs, files in os.walk(base_dir): for file in files: path = "%s/%s" % (root, file) if not handler.validate(): continue count += 1 if count > limit: break (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(path) data[path] = {"size": size} if count > limit: break paths = data.keys() paths.sort() sobjects = [] for path in paths: sobject = SearchType.create("sthpw/virtual") basename = os.path.basename(path) dirname = os.path.dirname(path) reldir = dirname.replace("%s" % base_dir, "") basename = os.path.basename(path) dirname = os.path.dirname(path) reldir = dirname.replace("%s" % base_dir, "") if not reldir: reldir = ' ' else: reldir.lstrip("/") if not basename: basename = ' ' sobject.set_value("folder", reldir) sobject.set_value("file_name", basename) sobjects.append(sobject) info = data.get(path) if info: sobject.set_value("size", info.get("size")) from tactic.ui.panel import TableLayoutWdg element_names = ['folder', 'file_name', 'size'] #element_names.extend( list(tags_keys) ) #show_metadata = False #if not show_metadata: # element_names.remove('metadata') #config_xml = self.get_config_xml(list(tags_keys)) #layout = TableLayoutWdg(search_type='sthpw/virtual', view='report', element_names=element_names, mode='simple') #layout.set_sobjects(sobjects) #top.add(layout) top.add("Matched %s items of %s<br/>" % (len(sobjects), total_count)) table = Table() table.add_color("color", "color") top.add(table) table.add_row() for element_name in element_names: title = Common.get_display_title(element_name) td = table.add_cell("<b>%s</b>" % title) td.add_border() td.add_color("color", "color", +5) td.add_gradient('background', 'background', -20) td.add_style("height: 20px") td.add_style("padding: 3px") for row, sobject in enumerate(sobjects): tr = table.add_row() if row % 2: background = tr.add_color("background", "background") else: background = tr.add_color("background", "background", -2) tr.add_attr("spt_background", background) for element_name in element_names: td = table.add_cell(sobject.get_value(element_name)) td.add_border() return top
def get_header_wdg(self): div = DivWdg() div.add_style("text-align: center") div.add_style("width: %s" % self.width) div.add("<hr/>") dots_div = DivWdg() #dots_div.add_style("margin: -28px auto 0px auto") dots_div.add_style("margin: -28px auto 0px auto") div.add(dots_div) left = 50 width = 50 dots_div.add_style("width", (left + width) * len(self.widgets) + left) for i, widget in enumerate(self.widgets): on_dot = DivWdg() on_dot.add_style("width: 20px") on_dot.add_style("height: 18px") on_dot.add_style("padding-top: 2px") on_dot.add_style("border-radius: 20px") on_dot.add_style("background: rgba(188,215,207,1.0)") on_dot.add_style("margin: 6 auto") #on_dot.add(" ") on_dot.add_border() #on_dot = IconWdg("", IconWdg.DOT_GREEN) on_dot.add_class("spt_wizard_on_dot") off_dot = DivWdg() off_dot.add_style("width: 12px") off_dot.add_style("height: 10px") off_dot.add_style("padding-top: 2px") off_dot.add_style("border-radius: 10px") #off_dot.add_style("background: rgba(215,188,207,1.0)") off_dot.add_style("background: #DDD") off_dot.add_style("margin: 11 auto 12 auto") #off_dot.add(" ") off_dot.add_border() #off_dot = IconWdg("", IconWdg.DOT_GREY) off_dot.add_class("spt_wizard_off_dot") if i == 0: off_dot.add_style("display: none") else: on_dot.add_style("display: none") dots_div.add_style("position: relative") dot_div = DivWdg() dot_div.add_style("text-align: center") dot_div.add_attr("spt_selected_index", i) dot_div.add_class("spt_wizard_link") dot_div.add_class("hand") dots_div.add(dot_div) dot_div.add(on_dot) dot_div.add(off_dot) dot_div.add_style("width: %spx" % width) dot_div.add_style("float: left") dot_div.add_style("margin-left: %spx" % left) dot_div.add_style("text-align: center") on_dot.add("%s" % (i + 1)) off_dot.add("%s" % (i + 1)) off_dot.add_style("font-size: 0.6em") on_dot.add_style("text-align: center") off_dot.add_style("text-align: center") name_div = DivWdg() dot_div.add(name_div) if i < len(self.titles): title = self.titles[i] else: title = widget.get_name() title = title.replace(".", " ") title = Common.get_display_title(title) #title = "%d %s" % (i+1, title) name_div.add(title) name_div.add_style("font-weight: bold") name_div.add_style("width: 80px") name_div.add_style("margin-left: -17px") div.add_relay_behavior({ 'type': 'mouseup', 'bvr_match_class': 'spt_wizard_link', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_wizard_top"); 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"); var selected_index = parseInt( bvr.src_el.getAttribute("spt_selected_index")); 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"); } page.setStyle("display", "none"); on_dot.setStyle("display", "none"); off_dot.setStyle("display", ""); } var back = top.getElement(".spt_wizard_back"); var next = top.getElement(".spt_wizard_next"); next.setStyle("display", ""); back.setStyle("display", ""); if (selected_index == 0) { back.setStyle("display", "none"); } else if (selected_index == pages.length-1) { next.setStyle("display", "none"); } var page = pages[selected_index]; page.setStyle("display", ""); page.addClass("spt_wizard_selected"); var on_dot = on_dots[selected_index]; var off_dot = off_dots[selected_index]; on_dot.setStyle("display", ""); off_dot.setStyle("display", "none"); ''' }) """ for i, widget in enumerate(self.widgets): name_div = DivWdg() div.add(name_div) name_div.add_class("spt_wizard_link") name_div.add_attr("spt_selected_index", i) name_div.add_class("hand") name_div.add_style("float: left") name_div.add_style("margin-left: %spx" % left) name = widget.get_name() name_div.add(name) name_div.add_style("width: %spx" % width) name_div.add_style("text-align: center") """ div.add("<br clear='all'/>") return div
def get_display(my): top = my.top my.set_as_panel(top) top.add_behavior( { 'type': 'load', 'cbjs_action': ''' spt.named_events.fire_event("side_bar|hide") ''' } ) top.add_style("width: 100%") top.add_color("background", "background", -10) top.add_style("padding-top: 10px") top.add_style("padding-bottom: 50px") top.add_class("spt_project_top") inner = DivWdg() top.add(inner) inner.add_style("width: 700px") inner.add_style("float: center") inner.add_border() inner.center() inner.add_style("padding: 30px") inner.add_color("background", "background") from tactic.ui.container import WizardWdg title = DivWdg() title.add("Create A New Project") wizard = WizardWdg(title=title, width="100%") inner.add(wizard) help_button = ActionButtonWdg(title="?", tip="Create Project 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("create-new-project"); ''' }) info_page = DivWdg() wizard.add(info_page, 'Info') info_page.add_class("spt_project_top") info_page.add_style("font-size: 12px") info_page.add_color("background", "background") info_page.add_color("color", "color") info_page.add_style("padding: 20px") from tactic.ui.input import TextInputWdg info_page.add("<b>Project Title:</b> ") text = TextWdg("project_title") text.add_behavior( { 'type': 'blur', 'cbjs_action': ''' if (bvr.src_el.value == '') { spt.alert("You must enter a project title"); return; } '''}) #text = TextInputWdg(title="project_title") info_page.add(text) text.add_style("width: 250px") info_page.add(HtmlElement.br(3)) span = DivWdg() info_page.add(span) span.add_style("padding: 20px 20px 20px 20px") span.add(IconWdg("INFO", IconWdg.CREATE)) span.add_color("background", "background3") span.add("The project title can be descriptive and contain spaces and special characters.") info_page.add("<br/><br/><hr/><br/><br/>") text.add_behavior( { 'type': 'change', 'cbjs_action': ''' var title = bvr.src_el.value; if (title.length > 100) { spt.alert("Title cannot exceed 100 characters."); return; } var code = spt.convert_to_alpha_numeric(title); code = code.substring(0,30); var top = bvr.src_el.getParent(".spt_project_top"); var code_el = top.getElement(".spt_project_code"); code_el.value = code; ''' } ) info_page.add("<b>Project Code: </b>") text = TextWdg("project_code") #text = TextInputWdg(title="project_code") text.add_behavior( { 'type': 'blur', 'cbjs_action': ''' var value = bvr.src_el.value; var code = spt.convert_to_alpha_numeric(value); bvr.src_el.value = code; if (code == '') { spt.alert("You must enter a project code."); return; } if (spt.input.has_special_chars(code)) { spt.alert("Project code cannot contain special characters."); return; } if (code.test(/^\d/)) { spt.alert("Project code cannot start with a number."); return; } if (code.length > 30) { spt.alert("Project code cannot exceed 30 characters."); return; } ''' } ) info_page.add(text) text.add_style("width: 250px") text.add_class("spt_project_code") info_page.add(HtmlElement.br(4)) span = DivWdg() info_page.add(span) span.add_style("padding: 20px 20px 20px 20px") span.add(IconWdg("INFO", IconWdg.CREATE)) span.add_color("background", "background3") span.add("The project code is a very important key that will tie many components of the project together.") span.add("<br/><br/>") span.add("* Note: the project code must contain only alphanumeric characters [A-Z]/[0-9] and only an '_' as a separator") info_page.add(span) info_page.add("<br/>"*2) projects = Project.get_all_projects() info_page.add("<b>Is Main Project? </b>") checkbox = CheckboxWdg("is_main_project") default_project_code = Config.get_value("install", "default_project") info_page.add(checkbox) if default_project_code: default_project = Project.get_by_code(default_project_code) else: default_project = None if default_project: default_title = default_project.get_value("title") info_span = SpanWdg() info_page.add(info_span) info_span.add("%sCurrent: %s (%s)" % (" "*3, default_title, default_project_code)) info_span.add_style("font-size: 0.9em") info_span.add_style("font-style: italic") else: if len(projects) == 0: checkbox.set_checked() info_page.add("<br/>"*2) span = DivWdg() info_page.add(span) span.add_style("padding: 20px 20px 20px 20px") span.add(IconWdg("INFO", IconWdg.CREATE)) span.add_color("background", "background3") span.add("A TACTIC installation can have multiple projects, but one can be designated as the main project. This project will appear at the root of the url. This is meant for building custom project launcher which is based on a main project.") span.add("<br/>"*2) span.add("* Note: TACTIC may need to be restarted in order for this to take effect") info_page.add(span) info_page.add("<br/>") # add an icon for this project image_div = DivWdg() wizard.add(image_div, 'Preview Image') image_div.add_class("spt_image_top") image_div.add_color("background", "background") image_div.add_color("color", "color") image_div.add_style("padding: 20px") image_div.add("<b>Project Image: </b>") image_div.add("<br/>"*3) on_complete = '''var server = TacticServerStub.get(); var file = spt.html5upload.get_file(); if (file) { var top = bvr.src_el.getParent(".spt_image_top"); var text = top.getElement(".spt_image_path"); var display = top.getElement(".spt_path_display"); var check_icon = top.getElement(".spt_check_icon"); var server = TacticServerStub.get(); var ticket = spt.Environment.get().get_ticket(); display.innerHTML = "Uploaded: " + file.name; display.setStyle("padding", "10px"); check_icon.setStyle("display", ""); var filename = file.name; filename = spt.path.get_filesystem_name(filename); var kwargs = { ticket: ticket, filename: filename } try { var ret_val = server.execute_cmd("tactic.command.CopyFileToAssetTempCmd", kwargs); var info = ret_val.info; var path = info.web_path; text.value = info.lib_path; display.innerHTML = display.innerHTML + "<br/><br/><div style='text-align: center'><img style='width: 80px;' src='"+path+"'/></div>"; } catch(e) { spt.alert(spt.exception.handler(e)); } spt.app_busy.hide(); } else { spt.alert('Error: file object cannot be found.') } spt.app_busy.hide(); ''' button = UploadButtonWdg(title="Browse", on_complete=on_complete) button.add_style("margin-left: auto") button.add_style("margin-right: auto") image_div.add(button) text = HiddenWdg("project_image_path") text.add_class("spt_image_path") image_div.add(text) check_div = DivWdg() image_div.add(check_div) check_div.add_class("spt_check_icon") check_icon = IconWdg("Image uploaded", IconWdg.CHECK) check_div.add(check_icon) check_div.add_style("display: none") check_div.add_style("float: left") check_div.add_style("padding-top: 8px") path_div = DivWdg() image_div.add(path_div) path_div.add_class("spt_path_display") image_div.add(HtmlElement.br(3)) span = DivWdg() image_div.add(span) span.add_style("padding: 20px 20px 20px 20px") span.add_color("background", "background3") span.add(IconWdg("INFO", IconWdg.CREATE)) span.add("The project image is a small image that will be used in various places as a visual representation of this project.") info_page.add("<br/><br/>") # get all of the template projects that are installed copy_div = DivWdg() wizard.add(copy_div, "Template") copy_div.add_style("padding-top: 20px") template = ActionButtonWdg(title="Manage", tip="Manage Templates") copy_div.add(template) template.add_style("float: right") template.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var class_name = 'tactic.ui.app.ProjectTemplateWdg' spt.panel.load_popup("Templates", class_name) ''' } ) template.add_style("margin-top: -5px") copy_div.add("<b>Copy From Template: </b>") search = Search("sthpw/project") search.add_filter("is_template", True) template_projects = search.get_sobjects() values = [x.get_value("code") for x in template_projects] labels = [x.get_value("title") for x in template_projects] # find all of the template projects installed template_dir = Environment.get_template_dir() import os if not os.path.exists(template_dir): paths = [] else: paths = os.listdir(template_dir); file_values = [] file_labels = [] for path in paths: if path.endswith("zip"): orig_path = '%s/%s'%(template_dir, path) path = path.replace(".zip", "") parts = path.split("-") plugin_code = parts[0] # skip if there is a matching project in the database #match_project = plugin_code.replace("_template", "") match_project = plugin_code old_style_plugin_code = re.sub( '_template$', '', plugin_code) if match_project in values: continue elif old_style_plugin_code in values: continue label = "%s (from file)" % Common.get_display_title(match_project) # for zip file, we want the path as well value = '%s|%s'%(plugin_code, orig_path) file_values.append(value) file_labels.append(label) if file_values: values.extend(file_values) labels.extend(file_labels) values.insert(0, "_empty") labels.insert(0, "- Empty Project -") select = SelectWdg("project_source") copy_div.add(select) select.set_option("values", values) select.set_option("labels", labels) #select.add_empty_option("-- Select --") select.add_behavior( { 'type': 'change', 'cbjs_action': ''' var value = bvr.src_el.value; var top = bvr.src_el.getParent(".spt_project_top"); var type = top.getElement(".spt_custom_project_top"); var namespace_option = top.getElement(".spt_custom_namespace_top"); var theme_el = top.getElement(".spt_theme_top"); if (bvr.src_el.value == "_empty") { spt.show(type); spt.show(namespace_option); spt.show(theme_el); } else { spt.hide(type); spt.hide(namespace_option); spt.hide(theme_el); } ''' } ) copy_div.add(HtmlElement.br(3)) span = DivWdg() copy_div.add(span) span.add_style("padding: 20px 20px 20px 20px") span.add(IconWdg("INFO", IconWdg.CREATE)) span.add_color("background", "background3") span.add("This will use the selected project template as a basis and copy all of the configuration elements. Only template projects should be copied.") #copy_div.add(HtmlElement.br(2)) #span = DivWdg("This will create an empty project with no predefined configuration.") #copy_div.add(span) # # Theme # theme_div = DivWdg() theme_div.add_class("spt_theme_top") theme_div.add_style("padding: 10px") theme_div.add_style("margin-top: 20px") copy_div.add(theme_div) theme_div.add("<b>Theme: </b> ") theme_div.add_style('padding-right: 6px') theme_select = SelectWdg('project_theme') theme_div.add(theme_select) # look in the plugins for all of the themes? from pyasm.biz import PluginUtil plugin_util = PluginUtil() data = plugin_util.get_plugins_data("theme") builtin_dir = Environment.get_builtin_plugin_dir() plugin_util = PluginUtil(base_dir=builtin_dir) data2 = plugin_util.get_plugins_data("theme") data = dict(data.items() + data2.items()) themes = data.keys() themes.sort() theme_select.set_option("values", themes) theme_select.add_empty_option('- No Theme -') default_theme = "TACTIC/default_theme" theme_select.set_value(default_theme) theme_select.add_behavior( { 'type': 'change', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_project_top"); var img_div = top.getElement(".spt_project_theme_div"); var theme = bvr.src_el.value; var img_els = img_div.getElements(".spt_project_theme_image"); for (var i = 0; i < img_els.length; i++) { if (theme == img_els[i].getAttribute("spt_theme") ) { img_els[i].setStyle("display", ""); } else { img_els[i].setStyle("display", "none"); } } ''' } ) theme_img_div = DivWdg() theme_div.add(theme_img_div) theme_img_div.add_class("spt_project_theme_div") for theme in themes: theme_item = DivWdg() theme_item.add_style("margin: 15px") theme_img_div.add(theme_item) theme_item.add_attr("spt_theme", theme) theme_item.add_class("spt_project_theme_image") if theme != default_theme: theme_item.add_style("display: none") table = Table() theme_item.add(table) table.add_row() if Environment.is_builtin_plugin(theme): theme_img = HtmlElement.img(src="/tactic/builtin_plugins/%s/media/screenshot.jpg" % theme) else: theme_img = HtmlElement.img(src="/tactic/plugins/%s/media/screenshot.jpg" % theme) theme_img.add_border() theme_img.set_box_shadow("1px 1px 1px 1px") theme_img.add_style("margin: 20px 10px") theme_img.add_style("width: 240px") plugin_data = data.get(theme) description = plugin_data.get("description") if not description: description = "No Description" table.add_cell(theme_img) table.add_cell( description ) theme_img_div.add_style("text-align: center") theme_img_div.add_style("margin: 10px") # # namespace # ns_div = DivWdg() ns_div.add_class("spt_custom_namespace_top") ns_div.add_style("padding: 10px") copy_div.add(ns_div) ns_div.add("<br/>") ns = HtmlElement.b("Namespace:") ns.add_style('padding-right: 6px') ns_div.add(ns) text = TextWdg('custom_namespace') text.add_class("spt_custom_namespace") text.add_behavior( { 'type': 'blur', 'cbjs_action': ''' var project_namespace = bvr.src_el.value; if (['sthpw','prod'].contains(project_namespace)) spt.alert('Namespace [' + project_namespace + '] is reserved.'); if (project_namespace.strip()=='') spt.alert('A "default" namespace will be used if you leave it empty.'); '''}) ns_div.add(text) hint = HintWdg('This will be used as the prefix for your sTypes. You can use your company name for instance') ns_div.add(hint) # is_template is_template_div = DivWdg() #is_template_div.add_style('display: none') is_template_div.add_class("spt_custom_project_top") is_template_div.add_style("padding: 10px") copy_div.add(is_template_div) is_template_div.add("<br/>") is_template_div.add("<b>Is this project a template: </b>") text = CheckboxWdg("custom_is_template") text.add_class("spt_custom_is_template") is_template_div.add(text) is_template_div.add(HtmlElement.br(2)) span = DivWdg("Template projects are used as a blueprint for generating new projects.") is_template_div.add(span) # Disabling for now ... advanced feature and may not be necessary #stypes_div = my.get_stypes_div() #is_template_div.add(stypes_div) last_page = DivWdg() wizard.add(last_page, "Complete") last_page.add_style("padding-top: 80px") last_page.add_style("padding-left: 30px") cb = RadioWdg('jump_project', label='Jump to New Project') cb.set_option("value", "project") #cb.set_option('disabled','disabled') cb.set_checked() last_page.add(cb) last_page.add(HtmlElement.br(2)) cb = RadioWdg('jump_project', label='Jump to Project Admin') cb.set_option("value", "admin") last_page.add(cb) last_page.add(HtmlElement.br(2)) cb = RadioWdg('jump_project', label='Create Another Project') cb.set_option("value", "new") last_page.add(cb) last_page.add(HtmlElement.br(5)) button_div = DivWdg() create_button = ActionButtonWdg(title="Create >>", tip="Create new project") wizard.add_submit_button(create_button) #button_div.add(create_button) create_button.add_style("float: right") create_button.add_behavior({ 'type': "click_up", 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_project_top"); var values = spt.api.Utility.get_input_values(top, null, null, null, {cb_boolean: true}); var project_code = values['project_code'][0]; if (project_code == '') { spt.alert("You must enter a project code."); return; } if (spt.input.has_special_chars(project_code)) { spt.alert("Project code cannot contain special characters."); return; } if (project_code.test(/^\d/)) { spt.alert("Project code cannot start with a number."); return; } if (values['project_title'] == '') { spt.alert("You must enter a project title"); return; } var project_source = values.project_source[0]; var project_image_path = values['project_image_path'][0]; var project_theme = values['project_theme'][0]; var options = { 'project_code': project_code, 'project_title': values['project_title'][0], 'project_image_path': project_image_path, 'project_theme': project_theme, } //'copy_pipelines': values['copy_pipelines'][0] var class_name; var busy_title; var busy_msg; var use_transaction; if (project_source == '') { spt.alert("Please select a template to copy or select create an empty project"); return; } else if (project_source != '_empty') { busy_title = "Copying Project"; busy_msg = "Copying project ["+project_source+"] ..."; use_transaction = false; class_name = 'tactic.command.ProjectTemplateInstallerCmd'; if (project_source.test(/\|/)) { var tmps = project_source.split('|'); project_source = tmps[0]; var path = tmps[1]; options['path'] = path; } options['template_code'] = project_source; options['force_database'] = true; } else { class_name = "tactic.command.CreateProjectCmd"; busy_title = "Creating New Project"; busy_msg = "Creating new project based on project info ..."; use_transaction = true; // use project code as the project type if namespace is not specified var project_namespace = values['custom_namespace'][0]; if (['sthpw','prod'].contains(project_namespace)) { spt.alert('Namespace [' + project_namespace + '] is reserved.'); return; } options['project_type'] = project_namespace ? project_namespace : project_code var is_template = values['custom_is_template']; if (is_template) { options['is_template'] = is_template[0]; } // This has been commented out in the UI //options['project_stype'] = values['project_stype'].slice(1); var is_main_project = values['is_main_project']; if (is_main_project) { options['is_main_project'] = is_main_project[0]; } } // Display app busy pop-up until create project command // has completed executing. spt.app_busy.show( busy_title, busy_msg ); setTimeout( function() { var ret_val = ''; var server = TacticServerStub.get(); try { ret_val = server.execute_cmd(class_name, options, {}, {use_transaction: true}); } catch(e) { spt.app_busy.hide(); spt.alert("Error: " + spt.exception.handler(e)); return; throw(e); } spt.api.Utility.clear_inputs(top); // show feedback at the end var jump = values['jump_project'][0]; if (jump == 'project' || jump == 'admin') { var location; if (jump == 'admin') { location = "/tactic/" + project_code + "/admin"; } else if (project_theme) { location = "/tactic/" + project_code + "/"; } else { location = "/tactic/" + project_code + "/admin/link/_startup"; } setTimeout( function() { document.location = location; }, 1000); } else { // Refresh header spt.panel.refresh(top); setTimeout( function() { spt.panel.refresh('ProjectSelectWdg'); }, 2800); spt.app_busy.hide(); } // don't hide because it gives the false impression that nothing // happened as it waits for the timeout //spt.app_busy.hide(); }, 0 ); ''' }) 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) inner.add(HtmlElement.br()) return top
def get_container(my, xml): # handle the container element_node = xml.get_node("config/tmp/element") attrs = Xml.get_attributes(element_node) element_name = attrs.get("name") show_resize_scroll = attrs.get("show_resize_scroll") if not show_resize_scroll: show_resize_scroll = my.kwargs.get("show_resize_scroll") if not show_resize_scroll: show_resize_scroll = "false" # look for attributes in the element tag for specifying a title action button to plug # into the title bar of the custom section ... # title_action_icon = attrs.get("title_action_icon") title_action_script = attrs.get("title_action_script") title_action_label = attrs.get("title_action_label") if title_action_script and not title_action_label: title_action_label = '[action]' # get the width and height for the element content ... width = attrs.get("width") height = attrs.get("height") if width and height: container = ContainerWdg( inner_width=width, inner_height=height, show_resize_scroll=show_resize_scroll ) else: container = ContainerWdg(show_resize_scroll=show_resize_scroll) # create the title title = attrs.get("title") if not title: title = Common.get_display_title(element_name) title_wdg = DivWdg() SmartMenu.assign_as_local_activator( title_wdg, 'HEADER_CTX' ) title_wdg.add_style("margin: 0px 0px 5px 0px") title_wdg.add_gradient("background", "background", 0) title_wdg.add_color("color", "color") title_wdg.add_style("padding", "5px") if title_action_script: # add an action button if an action script code was found in the attributes of the element proj = Project.get_project_code() script_search = Search("config/custom_script") script_sobj = script_search.get_by_search_key( "config/custom_script?project=%s&code=%s" % (proj, title_action_script) ) script = script_sobj.get_value('script') icon_str = "HELP" if title_action_icon: icon_str = title_action_icon action_btn = HtmlElement.img( IconWdg.get_icon_path(icon_str) ) action_btn.set_attr('title',title_action_label) # action_btn = IconWdg( title_action_label, icon=icon) action_btn.add_behavior( {'type': 'click_up', 'cbjs_action': script } ) action_btn.add_styles( "cursor: pointer; float: right;" ) title_wdg.add( action_btn ) title_wdg.add(title) container.add(title_wdg) return container
def get_display(my): search_key = my.kwargs.get("search_key") snapshot = my.kwargs.get("snapshot") if snapshot: my.snapshot = snapshot else: my.snapshot = SearchKey.get_by_search_key(search_key) assert my.snapshot metadata = my.snapshot.get_metadata() top = my.top top.add_color("background", "background") table = Table() table.set_max_width() top.add(table) table.set_unique_id() table.add_border() table.add_smart_styles("spt_cell", { 'padding': '3px' } ) tr = table.add_row() tr.add_gradient("background", "background3") th = table.add_header("Property") th.add_style("min-width: 200px") th.add_style("padding: 5px") th = table.add_header("Value") th.add_style("min-width: 400px") th.add_style("padding: 5px") keys = metadata.get("__keys__") if not keys: keys = metadata.keys() empty = False if not keys: empty = True keys = ['','','','','','',''] table.add_smart_styles("spt_cell", { 'height': '20px' } ) for i, key in enumerate(keys): value = metadata.get(key) title = Common.get_display_title(key) tr = table.add_row() if i % 2: tr.add_color("background", "background") tr.add_color("color", "color") else: tr.add_color("background", "background", -8) tr.add_color("color", "color") td = table.add_cell() td.add_class("spt_cell") td.add(title) td = table.add_cell() td.add_class("spt_cell") td.add(value) if empty: div = DivWdg() top.add(div) div.add_style("height: 30px") div.add_style("width: 150px") div.add_style("margin-top: -110px") div.center() div.add("<b>No Metadata</b>") div.add_border() div.add_color("background", "background3") div.add_color("color", "color3") div.add_style("padding: 20px") div.add_style("text-align: center") top.add_style("min-height: 200px") return top
def get_display(my): top = my.top top.add_class("spt_upload_top") title = my.kwargs.get("title") name = my.kwargs.get("name") if not name: name = "upload" if not title: title = Common.get_display_title(name) search_key = my.kwargs.get("search_key") hidden = HiddenWdg(name) top.add(hidden) multiple = my.kwargs.get("multiple") if multiple in [True, 'true']: multiple = True else: multiple = False if my.upload_id: upload_id = my.upload_id else: upload = Html5UploadWdg(name=name, multiple=multiple) top.add(upload) upload_id = upload.get_upload_id() from tactic.ui.widget import ActionButtonWdg button = ActionButtonWdg(title=title) button_id = my.kwargs.get("id") if button_id: button.set_id(button_id) top.add(button) upload_init = my.kwargs.get("upload_init") if not upload_init: upload_init = "" upload_start = my.kwargs.get("upload_start") if not upload_start: upload_start = ''' var top = bvr.src_el.getParent(".spt_upload_top"); var hidden = top.getElement(".spt_input"); var file = spt.html5upload.get_file(); if (!file) { return; } hidden.value = file.name; ''' on_complete = my.get_on_complete() if not on_complete: on_complete = ''' var files = spt.html5upload.get_files(); if (files.length == 0) { alert('Error: files cannot be found.') spt.app_busy.hide(); return; } spt.notify.show_message("Uploaded "+files.length+" files"); spt.app_busy.hide(); ''' upload_progress = my.kwargs.get("upload_progress") if not upload_progress: upload_progress = ''' var percent = Math.round(evt.loaded * 100 / evt.total); spt.app_busy.show("Uploading ["+percent+"%% complete]"); ''' reader_load = my.kwargs.get("reader_load") if not reader_load: reader_load = "" button.add_behavior( { 'type': 'click_up', 'upload_id': upload_id, 'search_key': search_key, 'ticket': my.ticket, 'multiple': multiple, 'kwargs': my.on_complete_kwargs, 'cbjs_action': ''' var search_key = bvr.search_key; // set the form if (!spt.html5upload.form) { spt.html5upload.set_form( $(bvr.upload_id) ); } spt.html5upload.clear(); spt.html5upload.kwargs = bvr.kwargs; var file_obj = spt.html5upload.form.getElement(".spt_file"); var is_multiple = bvr.multiple == true; var upload_start = function(evt) { %s; } var upload_progress = function(evt) { %s; } // set an action for completion var upload_complete = function(evt) { %s; spt.app_busy.hide(); } var reader_load = function(file) { %s; } var upload_file_kwargs = { reader_load: reader_load, upload_start: upload_start, upload_complete: upload_complete, upload_progress: upload_progress }; if (bvr.ticket) upload_file_kwargs['ticket'] = bvr.ticket; var onchange = function () { %s; spt.html5upload.upload_file(upload_file_kwargs); } if (is_multiple) { file_obj.setAttribute('multiple','multiple'); spt.html5upload.select_files(onchange); } else spt.html5upload.select_file(onchange); ''' % (upload_start, upload_progress, on_complete, reader_load, upload_init) } ) return top
def get_display(self): search_key = self.kwargs.get("search_key") snapshot = self.kwargs.get("snapshot") if snapshot: self.snapshot = snapshot else: self.snapshot = SearchKey.get_by_search_key(search_key) assert self.snapshot metadata = self.snapshot.get_metadata() top = self.top top.add_color("background", "background") table = Table() table.set_max_width() top.add(table) table.set_unique_id() table.add_border() table.add_smart_styles("spt_cell", {'padding': '3px'}) tr = table.add_row() tr.add_color("background", "background", -5) th = table.add_header("Property") th.add_style("min-width: 200px") th.add_style("padding: 5px") th = table.add_header("Value") th.add_style("min-width: 400px") th.add_style("padding: 5px") keys = metadata.get("__keys__") if not keys: keys = metadata.keys() empty = False if not keys: empty = True keys = ['', '', '', '', '', '', ''] table.add_smart_styles("spt_cell", {'height': '20px'}) for i, key in enumerate(keys): value = metadata.get(key) title = Common.get_display_title(key) tr = table.add_row() if i % 2: tr.add_color("background", "background") tr.add_color("color", "color") else: tr.add_color("background", "background", -8) tr.add_color("color", "color") td = table.add_cell() td.add_class("spt_cell") td.add(title) td = table.add_cell() td.add_class("spt_cell") td.add(value) if empty: div = DivWdg() top.add(div) div.add_style("height: 30px") div.add_style("width: 150px") div.add_style("margin-top: -110px") div.center() div.add("<b>No Metadata</b>") div.add_border() div.add_color("background", "background3") div.add_color("color", "color3") div.add_style("padding: 20px") div.add_style("text-align: center") top.add_style("min-height: 200px") return top
def get_versions_wdg(my): div = DivWdg() div.add_class("spt_imports") title_wdg = DivWdg() div.add(title_wdg) title_wdg.add("Imports found:") title_wdg.add_style("padding: 0px 0px 8px 0px") base_dir = my.kwargs.get("base_dir") imports_dir = "%s/imports" % base_dir if not os.path.exists(imports_dir): imports_dir = base_dir basenames = os.listdir(imports_dir) basenames.sort() basenames.reverse() div.add_relay_behavior({ 'type': 'mouseup', 'bvr_match_class': "spt_import_item", 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_imports"); var els = top.getElements(".spt_import_info"); for ( var i = 0; i < els.length; i++) { spt.hide(els[i]); } var el = bvr.src_el.getElement(".spt_import_info"); spt.show(el); ''' }) # find all the zip files count = 0 for basename in basenames: if not basename.endswith(".txt"): continue if basename.find("-files-") != -1: continue if basename.find("-data-") != -1: continue version_wdg = DivWdg() div.add(version_wdg) version_wdg.add_style("padding: 3px 3px 3px 12px") version_wdg.add_class("spt_import_item") radio = RadioWdg("basename") version_wdg.add(radio) radio.set_option("value", basename) if not count: radio.set_checked() version_wdg.add(basename) version_wdg.add("<br/>") # add info path = "%s/%s" % (imports_dir, basename) f = open(path) data = f.read() f.close() data = jsonloads(data) table = Table() version_wdg.add(table) table.add_class("spt_import_info") if count: table.add_style("display: none") table.set_max_width() table.add_style("margin-left: 40px") table.add_style("margin-right: 20px") version_wdg.add(table) for name, value in my.data.items(): name = Common.get_display_title(name) table.add_row() table.add_cell(name) table.add_cell(value) count += 1 if count == 0: msg_wdg = DivWdg() div.add(msg_wdg) msg_wdg.add("<i>No imports found</i>") msg_wdg.add_border() msg_wdg.add_style("padding: 20px") msg_wdg.add_style("padding: 10px") msg_wdg.add_style("text-align: center") msg_wdg.add_color("background", "background", -10) return div
def execute(my): project_code = my.kwargs.get("project_code") project_title = my.kwargs.get("project_title") project_type = my.kwargs.get("project_type") if not project_type: project_type = "simple" is_template = my.kwargs.get("is_template") project_theme = my.kwargs.get("project_theme") use_default_side_bar = my.kwargs.get("use_default_side_bar") if use_default_side_bar in [False, "false"]: use_default_side_bar = False else: use_default_side_bar = True assert project_code assert project_type if project_type: # check to see if it exists search = Search("sthpw/project_type") search.add_filter("code", project_type) project_type_sobj = search.get_sobject() if not project_type_sobj: # just create a default one in this case if it is named # after the project code if not is_template and project_type == project_code: project_type = "default" # create a new project type search = Search("sthpw/project_type") search.add_filter("code", project_type) project_type_sobj = search.get_sobject() if not project_type_sobj: project_type_sobj = SearchType.create("sthpw/project_type") project_type_sobj.set_value("code", project_type) project_type_sobj.set_value("type", "simple") project_type_sobj.commit() # set the current project to Admin Project.set_project("admin") # create a new project sobject project = SearchType.create("sthpw/project") project.set_value("code", project_code) project.set_value("title", project_title) project.set_value("type", project_type) # set the update of the database to current (this is obsolete) # project.set_value("last_db_update", "now()") project.set_value("last_version_update", "2.5.0.v01") if is_template in ["true", True, "True"]: project.set_value("is_template", True) else: project.set_value("is_template", False) if project_type != "default": category = Common.get_display_title(project_type) project.set_value("category", category) project.commit() # if there is an image, check it in upload_path = my.kwargs.get("project_image_path") if upload_path: if not os.path.exists(upload_path): raise TacticException("Cannot find upload image for project [%s]" % upload_path) file_type = "main" file_paths = [upload_path] file_types = [file_type] source_paths = [upload_path] from pyasm.biz import IconCreator if os.path.isfile(upload_path): icon_creator = IconCreator(upload_path) icon_creator.execute() web_path = icon_creator.get_web_path() icon_path = icon_creator.get_icon_path() if web_path: file_paths = [upload_path, web_path, icon_path] file_types = [file_type, "web", "icon"] from pyasm.checkin import FileCheckin checkin = FileCheckin(project, context="icon", file_paths=file_paths, file_types=file_types) checkin.execute() # find project's base_type base_type = project.get_base_type() if not base_type and project_type == "unittest": base_type = "unittest" elif not base_type: base_type = "simple" # get the database for this project db_resource = project.get_project_db_resource() database = db_resource.get_database_impl() # database = DatabaseImpl.get() database_type = database.get_database_type() if database_type == "Oracle": raise TacticException("Creation of project is not supported. Please create manually") # creating project database print "Creating database '%s' ..." % project_code try: # create the datbase database.create_database(db_resource) except Exception, e: print str(e) print "WARNING: Error creating database [%s]" % project_code
def execute(my): project_code = my.kwargs.get('project_code') project_title = my.kwargs.get('project_title') project_type = my.kwargs.get('project_type') if not project_type: project_type = "simple" is_template = my.kwargs.get('is_template') project_theme = my.kwargs.get('project_theme') use_default_side_bar = my.kwargs.get('use_default_side_bar') if use_default_side_bar in [False, 'false']: use_default_side_bar = False else: use_default_side_bar = True assert project_code assert project_type if project_type: # check to see if it exists search = Search("sthpw/project_type") search.add_filter("code", project_type) project_type_sobj = search.get_sobject() if not project_type_sobj: # just create a default one in this case if it is named # after the project code if not is_template and project_type == project_code: project_type = 'default' # create a new project type search = Search("sthpw/project_type") search.add_filter("code", project_type) project_type_sobj = search.get_sobject() if not project_type_sobj: project_type_sobj = SearchType.create("sthpw/project_type") project_type_sobj.set_value("code", project_type) project_type_sobj.set_value("type", "simple") project_type_sobj.commit() # set the current project to Admin Project.set_project("admin") # create a new project sobject project = SearchType.create("sthpw/project") project.set_value("code", project_code) project.set_value("title", project_title) project.set_value("type", project_type) # set the update of the database to current (this is obsolete) #project.set_value("last_db_update", "now()") project.set_value("last_version_update", "2.5.0.v01") if is_template in ['true', True, 'True']: project.set_value("is_template", True) else: project.set_value("is_template", False) if project_type != "default": category = Common.get_display_title(project_type) project.set_value("category", category) project.commit() # if there is an image, check it in upload_path = my.kwargs.get("project_image_path") if upload_path: if not os.path.exists(upload_path): raise TacticException( "Cannot find upload image for project [%s]" % upload_path) file_type = 'main' file_paths = [upload_path] file_types = [file_type] source_paths = [upload_path] from pyasm.biz import IconCreator if os.path.isfile(upload_path): icon_creator = IconCreator(upload_path) icon_creator.execute() web_path = icon_creator.get_web_path() icon_path = icon_creator.get_icon_path() if web_path: file_paths = [upload_path, web_path, icon_path] file_types = [file_type, 'web', 'icon'] from pyasm.checkin import FileCheckin checkin = FileCheckin(project, context='icon', file_paths=file_paths, file_types=file_types) checkin.execute() # find project's base_type base_type = project.get_base_type() if not base_type and project_type == 'unittest': base_type = 'unittest' elif not base_type: base_type = 'simple' # get the database for this project db_resource = project.get_project_db_resource() database = db_resource.get_database_impl() #database = DatabaseImpl.get() database_type = database.get_database_type() if database_type == 'Oracle': raise TacticException( "Creation of project is not supported. Please create manually") # creating project database print "Creating database '%s' ..." % project_code try: # create the datbase database.create_database(db_resource) except Exception, e: print str(e) print "WARNING: Error creating database [%s]" % project_code
def get_display(my): top = DivWdg() top.add_class("spt_wizard_top") my.height = my.kwargs.get("height") width = my.kwargs.get("width") if not width: width = "550px" inner = DivWdg() top.add(inner) inner.add_style("width: %s" % width) title = my.kwargs.get("title") if not title: title = "No Title" title_wdg = DivWdg() inner.add(title_wdg) title_wdg.add(title) title_wdg.add_style("font-size: 16px") title_wdg.add_style("font-weight: bold") inner.add("<br/>") views = my.kwargs.get("views") if views: from tactic.ui.panel import CustomLayoutWdg if isinstance(views, basestring): views = views.split("|") for view in views: title = Common.get_display_title(view) widget = CustomLayoutWdg(view=view) my.add(widget, title) header_wdg = my.get_header_wdg() inner.add(header_wdg) inner.add("<br/>") inner.add("<hr/>") for i, widget in enumerate(my.widgets): page_div = DivWdg() page_div.add_style("padding: 10px") page_div.add_style("min-height: 300px") if my.height: page_div.add_style("height: %s" % my.height) page_div.add_style("overflow-y: auto") if i != 0: page_div.add_style("display: none") else: page_div.add_class("spt_wizard_selected") page_div.add_class("spt_wizard_page") inner.add(page_div) page_div.add(widget) inner.add("<hr/>") bottom_wdg = my.get_bottom_wdg() inner.add(bottom_wdg) return top
def get_display(my): top = my.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="my_tasks_default" title="My Tasks"> <display class="tactic.ui.panel.ViewPanelWdg"> <search_type>sthpw/task</search_type> <show_shelf>false</show_shelf> <view>my_tasks_default</view> <target>spt_my_tasks_table_top</target> </display> </element> <!-- Menu item 2 --> <element ... > <display ... > <target ... /> </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 = my.kwargs.get("menu") config_xml = my.kwargs.get("config_xml") target = my.kwargs.get("target") # TODO: use_href to go to specific layout switcher view # use_href = my.kwrags.get("use_href") # Layout switcher button displays menu and assumes right hand position of screen 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}); var pointer = menu.getElement(".spt_popup_pointer"); pointer.setStyle("margin-left", menu_size.x - button_size.x); } ''' }) # menu_wdg menu_wdg = DivWdg() top.add(menu_wdg) menu_wdg.add_class("spt_switcher_menu") menu_wdg.add_style("display: none") menu_wdg.add_style("margin-top", "15px") menu_wdg.add_style("position", "absolute") menu_wdg.add_style("z-index", "10") 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") ''' }) # Pointer under activator pointer_wdg = DivWdg() menu_wdg.add(pointer_wdg) pointer_wdg.add(''' <div class="spt_first_arrow_div"> </div> <div class="spt_second_arrow_div"> </div> ''') pointer_wdg.add_class("spt_popup_pointer") style = HtmlElement.style(''' .spt_switcher_menu .spt_popup_pointer { z-index: 10; margin-top: -15px; margin-left: 100px; } .spt_switcher_menu .spt_first_arrow_div { border-color: rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) #ccc; 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_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; } ''') 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 = my.get_style() top.add(style) my.view = 'tab' config = WidgetConfig.get(view=my.view, xml=config_xml) element_names = config.get_element_names() 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") attrs = config.get_element_attributes(element_name) title = attrs.get("title") if not title: title = Common.get_display_title(element_name) item_div.add(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) item_div.add_behavior({ 'type': 'click_up', 'display_class': display_class, 'display_options': display_options, 'target': target, '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]; } var target = $(document.body).getElement("."+target_class); if (target) { spt.panel.load(target, bvr.display_class, bvr.display_options); } menu.setStyle("display", "none"); top.removeClass("spt_selected"); ''' }) return top
def get_display(self): top = self.top top.add_class("spt_upload_top") top.add_style("display: inline-block") title = self.kwargs.get("title") name = self.kwargs.get("name") if not name: name = "upload" if not title: title = Common.get_display_title(name) search_key = self.kwargs.get("search_key") hidden = HiddenWdg(name) top.add(hidden) multiple = self.kwargs.get("multiple") if multiple in [True, 'true']: multiple = True else: multiple = False if self.upload_id: upload_id = self.upload_id else: upload = Html5UploadWdg(name=name, multiple=multiple) top.add(upload) upload_id = upload.get_upload_id() button = self.get_activator_wdg(title) button_id = self.kwargs.get("id") if button_id: button.set_id(button_id) top.add(button) upload_init = self.kwargs.get("upload_init") if not upload_init: upload_init = "" upload_start = self.kwargs.get("upload_start") if not upload_start: upload_start = ''' var top = bvr.src_el.getParent(".spt_upload_top"); var hidden = top.getElement(".spt_input"); var file = spt.html5upload.get_file(); if (!file) { return; } hidden.value = file.name; ''' on_complete = self.get_on_complete() if not on_complete: on_complete = ''' var files = spt.html5upload.get_files(); if (files.length == 0) { alert('Error: files cannot be found.') spt.app_busy.hide(); return; } spt.notify.show_message("Uploaded "+files.length+" files"); spt.app_busy.hide(); ''' upload_progress = self.kwargs.get("upload_progress") if not upload_progress: upload_progress = ''' var percent = Math.round(evt.loaded * 100 / evt.total); spt.app_busy.show("Uploading ["+percent+"% complete]"); ''' reader_load = self.kwargs.get("reader_load") if not reader_load: reader_load = "" button.add_behavior({ 'type': 'click_up', 'upload_id': upload_id, 'search_key': search_key, 'ticket': self.ticket, 'multiple': multiple, 'kwargs': self.on_complete_kwargs, 'cbjs_action': ''' var search_key = bvr.search_key; // set the form if (!spt.html5upload.form) { spt.html5upload.set_form( $(bvr.upload_id) ); } spt.html5upload.clear(); spt.html5upload.kwargs = bvr.kwargs; var file_obj = spt.html5upload.form.getElement(".spt_file"); var is_multiple = bvr.multiple == true; var upload_start = function(evt) { %s; } var upload_progress = function(evt) { %s; } // set an action for completion var upload_complete = function(evt) { %s; spt.app_busy.hide(); } var reader_load = function(file) { %s; } var upload_file_kwargs = { reader_load: reader_load, upload_start: upload_start, upload_complete: upload_complete, upload_progress: upload_progress }; if (bvr.ticket) upload_file_kwargs['ticket'] = bvr.ticket; else if (spt.html5upload.ticket) { upload_file_kwargs['ticket'] = spt.html5upload.ticket; } var onchange = function () { %s; spt.html5upload.upload_file(upload_file_kwargs); } if (is_multiple) { file_obj.setAttribute('multiple','multiple'); spt.html5upload.select_files(onchange); } else spt.html5upload.select_file(onchange); ''' % (upload_start, upload_progress, on_complete, reader_load, upload_init) }) return top
def get_display(my): search_key = my.kwargs.get("search_key") path = my.kwargs.get("path") parser_str = my.kwargs.get("parser") use_tactic_tags = my.kwargs.get("use_tactic_tags") from pyasm.checkin import PILMetadataParser, ImageMagickMetadataParser, ExifMetadataParser, BaseMetadataParser if parser_str: parser = BaseMetadataParser.get_parser(parser_str, path) else: parser = BaseMetadataParser.get_parser_by_path(path) if parser: if use_tactic_tags in ['true', True]: metadata = parser.get_tactic_metadata() else: metadata = parser.get_metadata() else: metadata = {} top = my.top top.add_color("background", "background") table = Table() table.set_max_width() top.add(table) table.set_unique_id() table.add_border() table.add_smart_styles("spt_cell", { 'padding': '3px' } ) tr = table.add_row() tr.add_gradient("background", "background3") th = table.add_header("Property") th.add_style("min-width: 200px") th.add_style("padding: 5px") th = table.add_header("Value") th.add_style("min-width: 400px") th.add_style("padding: 5px") keys = metadata.get("__keys__") if not keys: keys = metadata.keys() empty = False if not keys: empty = True keys = ['','','','','','',''] table.add_smart_styles("spt_cell", { 'height': '20px' } ) for i, key in enumerate(keys): value = metadata.get(key) title = Common.get_display_title(key) tr = table.add_row() if i % 2: tr.add_color("background", "background") tr.add_color("color", "color") else: tr.add_color("background", "background", -8) tr.add_color("color", "color") td = table.add_cell() td.add_class("spt_cell") td.add(title) td = table.add_cell() td.add_class("spt_cell") if len(str(value)) > 500: inside = DivWdg() td.add(inside) value = value[:500] inside.add(value) inside.add_style("max-width: 600px") else: td.add(value) if empty: div = DivWdg() top.add(div) div.add_style("height: 30px") div.add_style("width: 150px") div.add_style("margin-top: -110px") div.center() div.add("<b>No Metadata</b>") div.add_border() div.add_color("background", "background3") div.add_color("color", "color3") div.add_style("padding: 20px") div.add_style("text-align: center") top.add_style("min-height: 200px") return top
def get_data(my, sobject): values = [] labels = [] if not my.config: return values, labels for element in my.elements: if element.startswith("{") and element.endswith("}"): expr = element.strip("{}") value = Search.eval(expr, sobject, single=True) labels.append(element) else: options = my.config.get_display_options(element) attrs = my.config.get_element_attributes(element) label = attrs.get('title') if not label: label = Common.get_display_title(element) labels.append(label) widget = my.widgets.get(element) if not widget: widget = my.config.get_display_widget(element) my.widgets[element] = widget widget.set_sobject(sobject) try: value = widget.get_text_value() except: value = 0 if isinstance(value, basestring): if value.endswith("%"): value = float( value.replace("%",'') ) else: value = 0 if not value: value = 0 #expression = options.get("expression") #if not expression: # value = 0 #else: # value = Search.eval(expression, sobject, single=True) if value > my.max_value: my.max_value = value values.append(value) return values, labels
def get_display(self): top = DivWdg() top.add_class("spt_wizard_top") self.height = self.kwargs.get("height") width = self.kwargs.get("width") if not width: width = "" self.width = width inner = DivWdg() top.add(inner) inner.add_style("width: %s" % width) title = self.kwargs.get("title") if not title: title = "none" if title != "none": title_wdg = DivWdg() inner.add(title_wdg) title_wdg.add(title) title_wdg.add_style("font-size: 16px") title_wdg.add_style("font-weight: bold") inner.add("<br/>") self.titles = self.kwargs.get("titles") if isinstance(self.titles, basestring): self.titles = self.titles.split("|") if not self.titles: self.titles = [] views = self.kwargs.get("views") if views: from tactic.ui.panel import CustomLayoutWdg if isinstance(views, basestring): views = views.split("|") for i, view in enumerate(views): if i < len(self.titles): title = self.titles[i] else: title = widget.get_name() title = title.replace(".", " ") title = Common.get_display_title(title) widget = CustomLayoutWdg(view=view) self.add(widget, title) header_wdg = self.get_header_wdg() inner.add(header_wdg) #header_wdg.add_color("background", "background", -5) header_wdg.add_class("spt_popup_header") inner.add("<br/>") inner.add("<hr/>") pages_div = DivWdg() pages_div.add_class("spt_popup_body") inner.add(pages_div) pages_div.add_style("overflow-y: auto") for i, widget in enumerate(self.widgets): page_div = DivWdg() page_div.add_class("spt_wizard_page") pages_div.add(page_div) page_div.add_style("padding: 10px") page_div.add_style("min-height: 300px") if self.height: page_div.add_style("height: %s" % self.height) page_div.add_style("overflow-y: auto") if i != 0: page_div.add_style("display: none") else: page_div.add_class("spt_wizard_selected") page_div.add(widget) pages_div.add("<hr/>") bottom_wdg = self.get_bottom_wdg() bottom_wdg.add_class("spt_popup_footer") inner.add(bottom_wdg) return top