Пример #1
0
    def get_stypes_div(my):
        div = DivWdg()
        #div.add("<hr/>")
        div.add_style("margin-top: 15px")

        title_div = DivWdg()
        title_div.add("<b>Add Custom Types</b>")
        div.add(title_div)
        title_div.add_style("margin-bottom: 10px")

        div.add("A project will manage one or more types of assets (Searchable Types or sTypes).  Here, extra custom sTypes, such as Shots, Assets, Artwork, etc. can be quickly defined that will be added to the new project. You can add more later in the Schema Editor.<br/>")
        from tactic.ui.container import DynamicListWdg
        dynlist_wdg = DynamicListWdg()
        div.add(dynlist_wdg)

        template_div = DivWdg()
        template_div.add_style("margin-top: 5px")
        template_div.add_style("margin-left: 10px")
        template_div.add("Type: ")
        text = TextWdg("project_stype")
        template_div.add(text)

        dynlist_wdg.add_template(template_div)

        first_div = DivWdg()
        first_div.add_style("margin-top: 5px")
        first_div.add_style("margin-left: 10px")
        first_div.add("Type: ")
        text = TextWdg("project_stype")
        first_div.add(text)
        dynlist_wdg.add_item(first_div)


        return div
Пример #2
0
    def get_display(self):

        top = self.top
        self.set_as_panel(top)
        top.add_class("spt_ingestion_top")
        top.add_color("background", "background", -5)

        self.data = {}

        rules_div = DivWdg()
        top.add(rules_div)
        rules_div.add_style("padding: 10px")

        rules_div.add("Rules: ")

        rules_select = SelectWdg("rule_code")
        rule_code = self.get_value('rule_code')
        if rule_code:
            rules_select.set_value(rule_code)
        rules_select.set_option("query", "config/ingest_rule|code|title")
        rules_select.add_empty_option("-- New --")
        rules_div.add(rules_select)
        rules_select.add_behavior( {
        'type': 'change',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_ingestion_top");
        value = bvr.src_el.value;
        var class_name = 'tactic.ui.tools.IngestionToolWdg';
        spt.panel.load(top, class_name, {rule_code: value} );
        '''
        } )

        rules_div.add("<hr/>")

        # read from the database
        if rule_code:
            search = Search("config/ingest_rule")
            search.add_filter("code", rule_code)
            sobject = search.get_sobject()
        else:
            sobject = None
        if sobject:
            self.data = sobject.get_value("data")
            if self.data:
                self.data = jsonloads(self.data)

        session_code = self.kwargs.get("session_code")
        if session_code:
            session = Search.get_by_code("config/ingest_session", session_code)
        else:
            if sobject:
                session = sobject.get_related_sobject("config/ingest_session")
                print("sobject: ", sobject.get_code(), sobject.get_value("spt_ingest_session_code"))
                print("parent: ", session)
            else:
                session = None


        if not session:
            #session = SearchType.create("config/ingest_session")
            #session.set_value("code", "session101")
            #session.set_value("location", "local")
            ##session.set_value("base_dir", "C:")
            top.add("No session defined!!!")
            return top



        rule = ""
        filter = ""
        ignore = ""


        # get the base path
        if sobject:
            base_dir = sobject.get_value("base_dir")
        else:
            base_dir = ''

        #else:
        #    base_dir = self.get_value("base_dir")
        #if not base_dir:
        #    base_dir = ''

        if sobject:
            title = sobject.get_value("title")
        else:
            title = ''

        if sobject:
            code = sobject.get_value("code")
        else:
            code = ''


        file_list = self.get_value("file_list")
        scan_type = self.get_value("scan_type")
        action_type = self.get_value("action_type")
        rule = self.get_value("rule")
        if not rule:
            rule = base_dir

        # get the rule for this path
        checkin_mode = "dir"
        depth = 0

        table = Table()
        rules_div.add(table)
        table.add_color("color", "color")


        from tactic.ui.input.text_input_wdg import TextInputWdg


        # add the title
        table.add_row()
        td = table.add_cell()
        td.add("Title: ")
        td = table.add_cell()

        text = TextInputWdg(name="title")
        td.add(text)
        if title:
            text.set_value(title)
        text.add_class("spt_title")
        text.add_style("width: 400px")
        #text.add_color("background", "background", -10)

        # add the optional code
        table.add_row()
        td = table.add_cell()
        td.add("Code (optional): ")
        td = table.add_cell()

        text = TextInputWdg(name="code")
        td.add(text)
        if code:
            text.set_value(code)
            text.set_readonly()
            text.add_color("background", "background", -10)
        text.add_class("spt_code")
        text.add_style("width: 400px")





        table.add_row()
        td = table.add_cell()
        td.add_style("height: 10px")
        td.add("<hr/>")


        table.add_row()
        td = table.add_cell()
        td.add("<b>Scan:</b><br/>")
        td.add("The following information will be used to find the paths that will be operated on by the ingestion process<br/><br/>")


        # add a scan type
        table.add_row()
        td = table.add_cell()
        td.add("Type: ")
        select = SelectWdg("scan_type")
        select.add_class("spt_scan_type")
        td = table.add_cell()
        td.add(select)
        select.set_value( self.get_value("action") )
        labels = ['Simple List', 'Rule', 'Script']
        values = ['list', 'rule', 'script']
        select.set_option("values", values)
        select.set_option("labels", labels)
        if scan_type:
            select.set_value(scan_type)

        table.add_row() 
        table.add_cell("&nbsp;")

        select.add_behavior( {
        'type': 'change',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_ingestion_top");
        value = bvr.src_el.value;

        var elements = top.getElements(".spt_scan_list");
        for (var i = 0; i < elements.length; i++) {
          if (value == 'list')
            spt.show(elements[i]);
          else
            spt.hide(elements[i]);
        }

        var elements = top.getElements(".spt_scan_rule");
        for (var i = 0; i < elements.length; i++) {
          if (value == 'rule')
            spt.show(elements[i]);
          else
            spt.hide(elements[i]);
        }
        var elements = top.getElements(".spt_scan_script");
        for (var i = 0; i < elements.length; i++) {
          if (value == 'script')
            spt.show(elements[i]);
          else
            spt.hide(elements[i]);
        }

        '''
        } )

        # add in a list of stuff
        tbody = table.add_tbody()
        tbody.add_class("spt_scan_list")
        if scan_type != 'list':
            tbody.add_style("display: none")

        tr = table.add_row()
        td = table.add_cell()
        td.add("List of files: ")
        td = table.add_cell()

        text = TextAreaWdg(name="file_list")
        td.add(text)
        text.add_style("width: 400px")
        #text.set_readonly()
        #text.add_color("background", "background", -10)
        text.set_value(file_list)

        table.close_tbody()



        # add rule scan mode
        tbody = table.add_tbody()
        tbody.add_class("spt_scan_rule")
        if scan_type != 'rule':
            tbody.add_style("display: none")



        # add the path
        tr = table.add_row()
        td = table.add_cell()
        td.add("Starting Path: ")
        td = table.add_cell()

        hidden = HiddenWdg("session_code", session.get_code() )
        td.add(hidden)

        text = TextInputWdg(name="base_dir")
        td.add(text)
        text.set_value(base_dir)
        text.add_style("width: 400px")
        #text.set_readonly()
        #text.add_color("background", "background", -10)
        text.set_value(base_dir)



        # add rule
        tr = table.add_row()
        td = table.add_cell()
        td.add("Tag Rule: ")
        td = table.add_cell()

        text = TextInputWdg(name="rule")
        td.add(text)
        text.add_style("width: 400px")
        text.set_value(rule)


        tr = table.add_row()
        td = table.add_cell()
        td.add("Filter: ")
        td = table.add_cell()
        text = TextWdg("filter")
        td.add(text)
        text.set_value( self.get_value("filter") )
        text.add_style("width: 400px")
        text.add_style("padding: 2px")
        text.add_style("-moz-border-radius: 5px")




        tr = table.add_row()
        td = table.add_cell()
        td.add("Ignore: ")
        td = table.add_cell()
        text = TextWdg("ignore")
        td.add(text)
        text.set_value( self.get_value("ignore") )
        text.set_value(ignore)
        text.add_style("width: 400px")
        text.add_style("padding: 2px")
        text.add_style("-moz-border-radius: 5px")


        table.add_row()
        td = table.add_cell()
        td.add("Validation script: ")
        td.add_style("vertical-align: top")
        td.add_style("padding-top: 5px")
        td = table.add_cell()
        text = TextInputWdg(name="validation_script")
        text.set_value( self.get_value("validation_script") )
        text.add_style("width: 400px")
        td.add(text)

        icon = IconButtonWdg(title='Edit Validation Script', icon=IconWdg.EDIT)
        icon.add_style("float: right")
        td.add(icon)
        icon.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        spt.named_events.fire_event("show_script_editor");

        var top = bvr.src_el.getParent(".spt_ingestion_top");
        var values = spt.api.Utility.get_input_values(top, null, false);

        var kwargs = {
            script_path: values.validation_script
        }
        setTimeout( function() {
        spt.js_edit.display_script_cbk(evt, kwargs)
        }, 500 );
        '''
        } )



        table.close_tbody()



        # add the script path
        tbody = table.add_tbody()
        tbody.add_class("spt_scan_script")
        if scan_type != 'script':
            tbody.add_style("display: none")


        tr = table.add_row()
        td = table.add_cell()
        td.add("Script Path: ")
        td = table.add_cell()

        text = TextInputWdg(name="script_path")
        td.add(text)
        text.add_style("width: 400px")


        table.close_tbody()



        table.add_row()
        td = table.add_cell("<hr/>")



        table.add_row()
        td = table.add_cell()
        td.add("<b>Action</b><br/>")
        td.add("The following information define the actions that will be used on each matched path<br/><br/>")


        # pick the type of action
        table.add_row()
        td = table.add_cell()
        td.add("Type: ")
        select = SelectWdg("action_type")
        td = table.add_cell()
        td.add(select)
        labels = ['Checkin', 'Ignore']
        values = ['checkin', 'ignore']
        select.set_option("values", values)
        select.set_option("labels", labels)
        select.add_empty_option("-- Select --")
        if action_type:
            select.set_value(action_type)

        select.add_behavior( {
        'type': 'change',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_ingestion_top");
        value = bvr.src_el.value;

        var elements = top.getElements(".spt_action_ignore");
        for (var i = 0; i < elements.length; i++) {
          if (value == 'ignore')
            spt.show(elements[i]);
          else
            spt.hide(elements[i]);
        }

        var elements = top.getElements(".spt_action_checkin");
        for (var i = 0; i < elements.length; i++) {
          if (value == 'checkin')
            spt.show(elements[i]);
          else
            spt.hide(elements[i]);
        }

        '''
        } )



        table.add_row()
        td = table.add_cell("<br/>")



        # add the script path
        tbody = table.add_tbody()
        tbody.add_class("spt_action_checkin")
        if action_type != 'checkin':
            tbody.add_style("display: none")



        # add the checkin type
        table.add_row()
        td = table.add_cell()
        td.add("Action: ")
        select = SelectWdg("action")
        td = table.add_cell()
        td.add(select)
        select.set_value( self.get_value("action") )
        labels = ['File Checkin', 'Directory Checkin', 'Sequence Checkin']
        values = ['file', 'directory', 'sequence', 'ignore']
        select.set_option("values", values)
        select.set_option("labels", labels)





        table.add_row()
        td = table.add_cell()
        td.add("Mode: ")
        select = SelectWdg("mode")
        td = table.add_cell()
        td.add(select)
        labels = ['Copy', 'Move', 'In Place']
        values = ['copy', 'move', 'inplace']
        select.set_option("values", values)
        select.set_option("labels", labels)






        # add the search_type
        table.add_row()
        td = table.add_cell()
        td.add("sType: ")
        td = table.add_cell()
        select = SelectWdg("search_type")
        td.add(select)
        search_types = Project.get().get_search_types()
        values = [x.get_value("search_type") for x in search_types]
        select.set_option("values", values)

        search_type = self.kwargs.get("search_type")
        if search_type:
            select.set_value(search_type)



        # add the search_type
        table.add_row()
        td = table.add_cell()
        td.add("Context: ")
        td = table.add_cell()
        select = SelectWdg("context")
        td.add(select)
        select.set_option("values", ['publish', 'by rule', 'custom'])




        # add extra values
        extra_div = DivWdg()
        text = TextWdg("extra_name")
        text.add_attr("spt_is_multiple", "true")
        extra_div.add(text)
        extra_div.add(" = ")
        text = TextWdg("extra_value")
        extra_div.add(text)
        text.add_attr("spt_is_multiple", "true")

        template_div = DivWdg()
        text = TextWdg("extra_name")
        text.add_attr("spt_is_multiple", "true")
        template_div.add(text)
        template_div.add(" = ")
        text = TextWdg("extra_value")
        template_div.add(text)
        text.add_attr("spt_is_multiple", "true")


        table.close_tbody()



        table.add_row()
        td = table.add_cell("<br/>")

        table.add_row()
        td = table.add_cell()
        td.add("Extra Keywords: ")
        td.add_style("vertical-align: top")
        td.add_style("padding-top: 5px")
        td = table.add_cell()
        text = TextWdg("keywords")
        text.add_style("width: 300px")
        td.add(text)





        table.add_row()
        td = table.add_cell()
        td.add("Extra Values: ")
        td.add_style("vertical-align: top")
        td.add_style("padding-top: 5px")
        td = table.add_cell()
        extra_list = DynamicListWdg()
        td.add(extra_list)
        extra_list.add_item(extra_div)
        extra_list.add_template(template_div)


        table.add_row()
        table.add_cell("&nbsp;")



        table.add_row()
        td = table.add_cell()
        td.add("Process script: ")
        td.add_style("vertical-align: top")
        td.add_style("padding-top: 5px")
        td = table.add_cell()
        text = TextWdg("process_script")
        text.add_style("width: 300px")
        td.add(text)
        text.set_value( self.get_value("process_script") )


        icon = IconButtonWdg(title='Edit Process Script', icon=IconWdg.EDIT)
        icon.add_style("float: right")
        td.add(icon)
        icon.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        spt.named_events.fire_event("show_script_editor");

        var top = bvr.src_el.getParent(".spt_ingestion_top");
        var values = spt.api.Utility.get_input_values(top, null, false);

        var kwargs = {
            script_path: values.process_script
        }

        // need to wait for this
        setTimeout( function() {
        spt.js_edit.display_script_cbk(evt, kwargs)
        }, 500 );
        '''
        } )



        table.add_row()
        td = table.add_cell()
        td.add("Custom Naming: ")
        td.add_style("vertical-align: top")
        td.add_style("padding-top: 5px")
        td = table.add_cell()
        text = TextWdg("naming")
        text.add_style("width: 300px")
        td.add(text)




        table.add_row()
        td = table.add_cell()

        #td.add("<br clear='all'/>")
        td.add("<hr/>")


        behavior = {
            'type': 'click_up',
            'cbjs_action': '''

            var top = bvr.src_el.getParent(".spt_ingestion_top");
            var values = spt.api.Utility.get_input_values(top, null, false);

            spt.app_busy.show("Scanning ...", values.base_dir);

            var class_name = 'tactic.ui.tools.IngestionProcessWdg';

            var server = TacticServerStub.get();
            values.mode = bvr.mode;

            values.is_local = 'true';

            // scan client side
            if (values.is_local == 'true') {
                var base_dir = values.base_dir;
                var applet = spt.Applet.get();
                var files = applet.list_recursive_dir(base_dir);
                // turn into a string
                var files_in_js = [];
                for (var i = 0; i < files.length; i++) {
                    var file = files[i].replace(/\\\\/g, "/");
                    files_in_js.push( file );
                }
                values.files = files_in_js;
                values.base_dir = base_dir;

                /*
                var server = TacticServerStub.get();
                var handoff_dir = server.get_handoff_dir();
                var applet = spt.Applet.get();
                for (var i = 0; i < files_in_js.length; i++) {
                    try {
                        var parts = files_in_js[i].split("/");
                        var filename = parts[parts.length-1];
                        spt.app_busy.show("Copying files to handoff", filename);
                        applet.copy_file(files_in_js[i], handoff_dir+"/"+filename);
                    } catch(e) {
                        log.error(e);
                    }

                }
                */
            }

            var info_el = top.getElement(".spt_info");
            spt.panel.load(info_el, class_name, values);
            spt.app_busy.hide();
            '''
        }


        # Save button
        button = ActionButtonWdg(title="Save", tip="Save Rule")
        td.add(button)
        button.add_style("float: right")
        behavior['mode'] = 'save'
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''

            var top = bvr.src_el.getParent(".spt_ingestion_top");
            var values = spt.api.Utility.get_input_values(top, null, false);
            spt.app_busy.show("Saving ...");

            var class_name = 'tactic.command.CheckinRuleSaveCmd';
            var server = TacticServerStub.get();
            server.execute_cmd(class_name, values);

            spt.panel.refresh(top, {});

            spt.app_busy.hide();

            '''
        } )



 
        # Scan button
        button = ActionButtonWdg(title="Scan", tip="Click to Scan")
        td.add(button)
        button.add_style("float: left")


        # set a limit
        #limit = TextWdg("limit")
        #td.add(limit)
        #text.add_style("float: left")


        behavior = behavior.copy()
        behavior['mode'] = 'scan'
        button.add_behavior(behavior)

        # Test button
        button = ActionButtonWdg(title="Test", tip="Do a test of this rule")
        td.add(button)
        behavior = behavior.copy()
        behavior['mode'] = 'test'
        button.add_behavior(behavior)
        button.add_style("float: left")




        # Ingest button
        button = ActionButtonWdg(title="Ingest", tip="Click to start ingesting")
        td.add(button)
        behavior = behavior.copy()
        behavior['mode'] = 'checkin'
        button.add_behavior(behavior)



        table.add_behavior( {
            'type': 'listen',
            'event_name': 'file_browser|select',
            'cbjs_action': '''
            var dirname = bvr.firing_data.dirname;
            var top = bvr.src_el.getParent(".spt_ingestion_top");
            var kwargs = {
              base_dir: dirname
            };

            spt.panel.load(top, top.getAttribute("spt_class_name"), kwargs);
            '''
        })


        top.add( self.get_info_wdg() )

        return top
Пример #3
0
    def get_display(my):

        data = my.kwargs.get('kwargs')
        if data:
            data = jsonloads(data)
            my.kwargs.update(data)


        my.search_type = my.kwargs.get("search_type")

        my.x_axis = my.kwargs.get("x_axis")
        if not my.x_axis:
            my.x_axis = 'code'

        my.y_axis = my.kwargs.get("y_axis")
        if type(my.y_axis) == types.ListType:
            my.y_axis = "|".join( my.y_axis )

        my.chart_type = my.kwargs.get("chart_type")
        if not my.chart_type:
            my.chart_type = 'bar'

        # get any search keys if any are passed in
        my.search_keys = my.kwargs.get("search_keys")


        top = DivWdg()
        top.add_class("spt_chart_builder")
        top.add_color("background", "background")
        top.add_border()



        from tactic.ui.app import HelpButtonWdg
        help_button = HelpButtonWdg(alias='charting')
        top.add( help_button )
        help_button.add_style("float: right")

        


        project = Project.get()
        search_types = project.get_search_types(include_sthpw=True)
        search_types = [x.get_value("search_type") for x in search_types]

        build_div = DivWdg()

        from pyasm.widget import SwapDisplayWdg
        swap_wdg = SwapDisplayWdg.get_triangle_wdg()
        swap_script = swap_wdg.get_swap_script()
        build_div.add(swap_wdg)

        build_div.add("<b>Chart Specifications</b>")
        build_div.add_style("margin-bottom: 5px")
        build_div.add_style("height: 25px")
        build_div.add_style("padding-top: 5px")
        build_div.add_gradient("background", "background", -10)
        build_div.add_color("color", "color")


        build_div.add_class("hand")
        build_div.add_class("SPT_DTS")
        top.add(build_div)
        build_div.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_chart_builder");
            var spec = top.getElement(".spt_chart_spec");
            //spt.api.toggle_show_hide(spec);
            spt.toggle_show_hide(spec);
            %s;
            ''' % swap_script
        } )

        spec_div = DivWdg()
        spec_div.add_color("color", "color3")
        spec_div.add_color("background", "background3")
        spec_div.add_class("spt_chart_spec")
        spec_div.add_border()
        spec_div.add_style("padding: 10px")
        spec_div.add_style("margin: 5px")
        spec_div.add_style("display: none")
        top.add(spec_div)

        table = Table()
        table.add_color("color", "color3")
        spec_div.add(table)

        # add the search type selector
        table.add_row()
        table.add_cell("Search Type: ")

        search_type_div = DivWdg()
        search_type_select = TextWdg("search_type")
        search_type_select.set_value(my.search_type)
        #search_type_select.set_option("values", search_types)
        search_type_div.add(search_type_select)
        table.add_cell(search_type_div)

        # add the chart type selector
        table.add_row()
        table.add_cell("Chart Type: ")

        type_div = DivWdg()
        #type_div.add_style("padding: 3px")
        type_select = SelectWdg("chart_type")
        type_select.set_option("values", "line|bar|area")
        if my.chart_type:
            type_select.set_value(my.chart_type)
        type_div.add(type_select)
        table.add_cell(type_div)

        # add the chart type selector
        table.add_row()
        table.add_cell("X-Axis: ")

        # need to find all expression widgets or use get_text_value()?
        x_axis_div = DivWdg()
        x_axis_text = TextWdg("x_axis")
        x_axis_text.set_value("code")
        x_axis_div.add(x_axis_text)
        table.add_cell(x_axis_div)



        # add the chart type selector
        table.add_row()
        td = table.add_cell("Y-Axis: ")
        td.add_style("vertical-align: top")

        y_axis_div = DivWdg()
        #y_axis_text = TextWdg("y_axis")
        #if my.y_axis:
        #    y_axis_text.set_value(my.y_axis)
        #y_axis_div.add(y_axis_text)
        td = table.add_cell(y_axis_div)

        # add in a list of entries
        from tactic.ui.container import DynamicListWdg
        list_wdg = DynamicListWdg()
        for value in my.y_axis.split("|"):
            item = TextWdg("y_axis")
            item.set_value(value, set_form_value=False)
            list_wdg.add_item(item)
        y_axis_div.add(list_wdg)



        spec_div.add("<br/>")
        from tactic.ui.widget import ActionButtonWdg
        button = ActionButtonWdg(title="Refresh")
        spec_div.add(button)
        spec_div.add(HtmlElement.br(2))
        button.add_style("float: left")

        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_chart_builder");
        var chart = top.getElement(".spt_chart");
        var values = spt.api.get_input_values(top);
        //var values = spt.api.Utility.get_input_values(top);
        spt.panel.refresh(chart, values);
        '''
        } )

        #TODO: provide a field for user to type in the chart name
        """

        button = ActionButtonWdg(title="Save")
        spec_div.add(button)
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_chart_builder");
        var chart = top.getElement(".spt_chart");
        var values = spt.api.get_input_values(top);

        var login = '******';
        var search_type = 'SideBarWdg';
        var side_bar_view = 'project_view';
        var unique_el_name = 'chart_test'

        var kwargs = {};
        kwargs['login'] = null;
        //if (save_as_personal) 
        //    kwargs['login'] = login;
        kwargs['class_name'] = 'tactic.ui.chart.ChartBuilderWdg';

        var display_options = {};
        display_options['search_type'] = 'prod/asset'
        kwargs['display_options'] = display_options;
 
        kwargs['unique'] = true;
        //if (new_title)
        //    kwargs['element_attrs'] = {'title': new_title}; 

        var server = TacticServerStub.get()
        server.add_config_element(search_type, side_bar_view, unique_el_name, kwargs);
        spt.panel.refresh("side_bar");
        '''
        } )
        """

        width = '600px'
        kwargs = {
            'y_axis': my.y_axis,
            'chart_type': my.chart_type,
            'search_type': my.search_type,
            'width': width,
            'search_keys': my.search_keys
        }

        chart_div = DivWdg()
        chart = BarChartWdg(**kwargs)

        chart_div.add(chart)
        top.add(chart_div)


        #from chart2_wdg import SampleSObjectChartWdg
        #chart = SampleSObjectChartWdg(**kwargs)
        #chart_div.add(chart)





        return top
Пример #4
0
    def get_display(self):

        top = self.top
        self.set_as_panel(top)
        top.add_class("spt_ingestion_top")
        top.add_color("background", "background", -5)

        self.data = {}

        rules_div = DivWdg()
        top.add(rules_div)
        rules_div.add_style("padding: 10px")

        rules_div.add("Rules: ")

        rules_select = SelectWdg("rule_code")
        rule_code = self.get_value('rule_code')
        if rule_code:
            rules_select.set_value(rule_code)
        rules_select.set_option("query", "config/ingest_rule|code|title")
        rules_select.add_empty_option("-- New --")
        rules_div.add(rules_select)
        rules_select.add_behavior({
            'type':
            'change',
            'cbjs_action':
            '''
        var top = bvr.src_el.getParent(".spt_ingestion_top");
        value = bvr.src_el.value;
        var class_name = 'tactic.ui.tools.IngestionToolWdg';
        spt.panel.load(top, class_name, {rule_code: value} );
        '''
        })

        rules_div.add("<hr/>")

        # read from the database
        if rule_code:
            search = Search("config/ingest_rule")
            search.add_filter("code", rule_code)
            sobject = search.get_sobject()
        else:
            sobject = None
        if sobject:
            self.data = sobject.get_value("data")
            if self.data:
                self.data = jsonloads(self.data)

        session_code = self.kwargs.get("session_code")
        if session_code:
            session = Search.get_by_code("config/ingest_session", session_code)
        else:
            if sobject:
                session = sobject.get_related_sobject("config/ingest_session")
                print("sobject: ", sobject.get_code(),
                      sobject.get_value("spt_ingest_session_code"))
                print("parent: ", session)
            else:
                session = None

        if not session:
            #session = SearchType.create("config/ingest_session")
            #session.set_value("code", "session101")
            #session.set_value("location", "local")
            ##session.set_value("base_dir", "C:")
            top.add("No session defined!!!")
            return top

        rule = ""
        filter = ""
        ignore = ""

        # get the base path
        if sobject:
            base_dir = sobject.get_value("base_dir")
        else:
            base_dir = ''

        #else:
        #    base_dir = self.get_value("base_dir")
        #if not base_dir:
        #    base_dir = ''

        if sobject:
            title = sobject.get_value("title")
        else:
            title = ''

        if sobject:
            code = sobject.get_value("code")
        else:
            code = ''

        file_list = self.get_value("file_list")
        scan_type = self.get_value("scan_type")
        action_type = self.get_value("action_type")
        rule = self.get_value("rule")
        if not rule:
            rule = base_dir

        # get the rule for this path
        checkin_mode = "dir"
        depth = 0

        table = Table()
        rules_div.add(table)
        table.add_color("color", "color")

        from tactic.ui.input.text_input_wdg import TextInputWdg

        # add the title
        table.add_row()
        td = table.add_cell()
        td.add("Title: ")
        td = table.add_cell()

        text = TextInputWdg(name="title")
        td.add(text)
        if title:
            text.set_value(title)
        text.add_class("spt_title")
        text.add_style("width: 400px")
        #text.add_color("background", "background", -10)

        # add the optional code
        table.add_row()
        td = table.add_cell()
        td.add("Code (optional): ")
        td = table.add_cell()

        text = TextInputWdg(name="code")
        td.add(text)
        if code:
            text.set_value(code)
            text.set_readonly()
            text.add_color("background", "background", -10)
        text.add_class("spt_code")
        text.add_style("width: 400px")

        table.add_row()
        td = table.add_cell()
        td.add_style("height: 10px")
        td.add("<hr/>")

        table.add_row()
        td = table.add_cell()
        td.add("<b>Scan:</b><br/>")
        td.add(
            "The following information will be used to find the paths that will be operated on by the ingestion process<br/><br/>"
        )

        # add a scan type
        table.add_row()
        td = table.add_cell()
        td.add("Type: ")
        select = SelectWdg("scan_type")
        select.add_class("spt_scan_type")
        td = table.add_cell()
        td.add(select)
        select.set_value(self.get_value("action"))
        labels = ['Simple List', 'Rule', 'Script']
        values = ['list', 'rule', 'script']
        select.set_option("values", values)
        select.set_option("labels", labels)
        if scan_type:
            select.set_value(scan_type)

        table.add_row()
        table.add_cell("&nbsp;")

        select.add_behavior({
            'type':
            'change',
            'cbjs_action':
            '''
        var top = bvr.src_el.getParent(".spt_ingestion_top");
        value = bvr.src_el.value;

        var elements = top.getElements(".spt_scan_list");
        for (var i = 0; i < elements.length; i++) {
          if (value == 'list')
            spt.show(elements[i]);
          else
            spt.hide(elements[i]);
        }

        var elements = top.getElements(".spt_scan_rule");
        for (var i = 0; i < elements.length; i++) {
          if (value == 'rule')
            spt.show(elements[i]);
          else
            spt.hide(elements[i]);
        }
        var elements = top.getElements(".spt_scan_script");
        for (var i = 0; i < elements.length; i++) {
          if (value == 'script')
            spt.show(elements[i]);
          else
            spt.hide(elements[i]);
        }

        '''
        })

        # add in a list of stuff
        tbody = table.add_tbody()
        tbody.add_class("spt_scan_list")
        if scan_type != 'list':
            tbody.add_style("display: none")

        tr = table.add_row()
        td = table.add_cell()
        td.add("List of files: ")
        td = table.add_cell()

        text = TextAreaWdg(name="file_list")
        td.add(text)
        text.add_style("width: 400px")
        #text.set_readonly()
        #text.add_color("background", "background", -10)
        text.set_value(file_list)

        table.close_tbody()

        # add rule scan mode
        tbody = table.add_tbody()
        tbody.add_class("spt_scan_rule")
        if scan_type != 'rule':
            tbody.add_style("display: none")

        # add the path
        tr = table.add_row()
        td = table.add_cell()
        td.add("Starting Path: ")
        td = table.add_cell()

        hidden = HiddenWdg("session_code", session.get_code())
        td.add(hidden)

        text = TextInputWdg(name="base_dir")
        td.add(text)
        text.set_value(base_dir)
        text.add_style("width: 400px")
        #text.set_readonly()
        #text.add_color("background", "background", -10)
        text.set_value(base_dir)

        # add rule
        tr = table.add_row()
        td = table.add_cell()
        td.add("Tag Rule: ")
        td = table.add_cell()

        text = TextInputWdg(name="rule")
        td.add(text)
        text.add_style("width: 400px")
        text.set_value(rule)

        tr = table.add_row()
        td = table.add_cell()
        td.add("Filter: ")
        td = table.add_cell()
        text = TextWdg("filter")
        td.add(text)
        text.set_value(self.get_value("filter"))
        text.add_style("width: 400px")
        text.add_style("padding: 2px")
        text.add_style("-moz-border-radius: 5px")

        tr = table.add_row()
        td = table.add_cell()
        td.add("Ignore: ")
        td = table.add_cell()
        text = TextWdg("ignore")
        td.add(text)
        text.set_value(self.get_value("ignore"))
        text.set_value(ignore)
        text.add_style("width: 400px")
        text.add_style("padding: 2px")
        text.add_style("-moz-border-radius: 5px")

        table.add_row()
        td = table.add_cell()
        td.add("Validation script: ")
        td.add_style("vertical-align: top")
        td.add_style("padding-top: 5px")
        td = table.add_cell()
        text = TextInputWdg(name="validation_script")
        text.set_value(self.get_value("validation_script"))
        text.add_style("width: 400px")
        td.add(text)

        icon = IconButtonWdg(title='Edit Validation Script', icon=IconWdg.EDIT)
        icon.add_style("float: right")
        td.add(icon)
        icon.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
        spt.named_events.fire_event("show_script_editor");

        var top = bvr.src_el.getParent(".spt_ingestion_top");
        var values = spt.api.Utility.get_input_values(top, null, false);

        var kwargs = {
            script_path: values.validation_script
        }
        setTimeout( function() {
        spt.js_edit.display_script_cbk(evt, kwargs)
        }, 500 );
        '''
        })

        table.close_tbody()

        # add the script path
        tbody = table.add_tbody()
        tbody.add_class("spt_scan_script")
        if scan_type != 'script':
            tbody.add_style("display: none")

        tr = table.add_row()
        td = table.add_cell()
        td.add("Script Path: ")
        td = table.add_cell()

        text = TextInputWdg(name="script_path")
        td.add(text)
        text.add_style("width: 400px")

        table.close_tbody()

        table.add_row()
        td = table.add_cell("<hr/>")

        table.add_row()
        td = table.add_cell()
        td.add("<b>Action</b><br/>")
        td.add(
            "The following information define the actions that will be used on each matched path<br/><br/>"
        )

        # pick the type of action
        table.add_row()
        td = table.add_cell()
        td.add("Type: ")
        select = SelectWdg("action_type")
        td = table.add_cell()
        td.add(select)
        labels = ['Checkin', 'Ignore']
        values = ['checkin', 'ignore']
        select.set_option("values", values)
        select.set_option("labels", labels)
        select.add_empty_option("-- Select --")
        if action_type:
            select.set_value(action_type)

        select.add_behavior({
            'type':
            'change',
            'cbjs_action':
            '''
        var top = bvr.src_el.getParent(".spt_ingestion_top");
        value = bvr.src_el.value;

        var elements = top.getElements(".spt_action_ignore");
        for (var i = 0; i < elements.length; i++) {
          if (value == 'ignore')
            spt.show(elements[i]);
          else
            spt.hide(elements[i]);
        }

        var elements = top.getElements(".spt_action_checkin");
        for (var i = 0; i < elements.length; i++) {
          if (value == 'checkin')
            spt.show(elements[i]);
          else
            spt.hide(elements[i]);
        }

        '''
        })

        table.add_row()
        td = table.add_cell("<br/>")

        # add the script path
        tbody = table.add_tbody()
        tbody.add_class("spt_action_checkin")
        if action_type != 'checkin':
            tbody.add_style("display: none")

        # add the checkin type
        table.add_row()
        td = table.add_cell()
        td.add("Action: ")
        select = SelectWdg("action")
        td = table.add_cell()
        td.add(select)
        select.set_value(self.get_value("action"))
        labels = ['File Checkin', 'Directory Checkin', 'Sequence Checkin']
        values = ['file', 'directory', 'sequence', 'ignore']
        select.set_option("values", values)
        select.set_option("labels", labels)

        table.add_row()
        td = table.add_cell()
        td.add("Mode: ")
        select = SelectWdg("mode")
        td = table.add_cell()
        td.add(select)
        labels = ['Copy', 'Move', 'In Place']
        values = ['copy', 'move', 'inplace']
        select.set_option("values", values)
        select.set_option("labels", labels)

        # add the search_type
        table.add_row()
        td = table.add_cell()
        td.add("sType: ")
        td = table.add_cell()
        select = SelectWdg("search_type")
        td.add(select)
        search_types = Project.get().get_search_types()
        values = [x.get_value("search_type") for x in search_types]
        select.set_option("values", values)

        search_type = self.kwargs.get("search_type")
        if search_type:
            select.set_value(search_type)

        # add the search_type
        table.add_row()
        td = table.add_cell()
        td.add("Context: ")
        td = table.add_cell()
        select = SelectWdg("context")
        td.add(select)
        select.set_option("values", ['publish', 'by rule', 'custom'])

        # add extra values
        extra_div = DivWdg()
        text = TextWdg("extra_name")
        text.add_attr("spt_is_multiple", "true")
        extra_div.add(text)
        extra_div.add(" = ")
        text = TextWdg("extra_value")
        extra_div.add(text)
        text.add_attr("spt_is_multiple", "true")

        template_div = DivWdg()
        text = TextWdg("extra_name")
        text.add_attr("spt_is_multiple", "true")
        template_div.add(text)
        template_div.add(" = ")
        text = TextWdg("extra_value")
        template_div.add(text)
        text.add_attr("spt_is_multiple", "true")

        table.close_tbody()

        table.add_row()
        td = table.add_cell("<br/>")

        table.add_row()
        td = table.add_cell()
        td.add("Extra Keywords: ")
        td.add_style("vertical-align: top")
        td.add_style("padding-top: 5px")
        td = table.add_cell()
        text = TextWdg("keywords")
        text.add_style("width: 300px")
        td.add(text)

        table.add_row()
        td = table.add_cell()
        td.add("Extra Values: ")
        td.add_style("vertical-align: top")
        td.add_style("padding-top: 5px")
        td = table.add_cell()
        extra_list = DynamicListWdg()
        td.add(extra_list)
        extra_list.add_item(extra_div)
        extra_list.add_template(template_div)

        table.add_row()
        table.add_cell("&nbsp;")

        table.add_row()
        td = table.add_cell()
        td.add("Process script: ")
        td.add_style("vertical-align: top")
        td.add_style("padding-top: 5px")
        td = table.add_cell()
        text = TextWdg("process_script")
        text.add_style("width: 300px")
        td.add(text)
        text.set_value(self.get_value("process_script"))

        icon = IconButtonWdg(title='Edit Process Script', icon=IconWdg.EDIT)
        icon.add_style("float: right")
        td.add(icon)
        icon.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
        spt.named_events.fire_event("show_script_editor");

        var top = bvr.src_el.getParent(".spt_ingestion_top");
        var values = spt.api.Utility.get_input_values(top, null, false);

        var kwargs = {
            script_path: values.process_script
        }

        // need to wait for this
        setTimeout( function() {
        spt.js_edit.display_script_cbk(evt, kwargs)
        }, 500 );
        '''
        })

        table.add_row()
        td = table.add_cell()
        td.add("Custom Naming: ")
        td.add_style("vertical-align: top")
        td.add_style("padding-top: 5px")
        td = table.add_cell()
        text = TextWdg("naming")
        text.add_style("width: 300px")
        td.add(text)

        table.add_row()
        td = table.add_cell()

        #td.add("<br clear='all'/>")
        td.add("<hr/>")

        behavior = {
            'type':
            'click_up',
            'cbjs_action':
            '''

            var top = bvr.src_el.getParent(".spt_ingestion_top");
            var values = spt.api.Utility.get_input_values(top, null, false);

            spt.app_busy.show("Scanning ...", values.base_dir);

            var class_name = 'tactic.ui.tools.IngestionProcessWdg';

            var server = TacticServerStub.get();
            values.mode = bvr.mode;

            values.is_local = 'true';

            // scan client side
            if (values.is_local == 'true') {
                var base_dir = values.base_dir;
                var applet = spt.Applet.get();
                var files = applet.list_recursive_dir(base_dir);
                // turn into a string
                var files_in_js = [];
                for (var i = 0; i < files.length; i++) {
                    var file = files[i].replace(/\\\\/g, "/");
                    files_in_js.push( file );
                }
                values.files = files_in_js;
                values.base_dir = base_dir;

                /*
                var server = TacticServerStub.get();
                var handoff_dir = server.get_handoff_dir();
                var applet = spt.Applet.get();
                for (var i = 0; i < files_in_js.length; i++) {
                    try {
                        var parts = files_in_js[i].split("/");
                        var filename = parts[parts.length-1];
                        spt.app_busy.show("Copying files to handoff", filename);
                        applet.copy_file(files_in_js[i], handoff_dir+"/"+filename);
                    } catch(e) {
                        log.error(e);
                    }

                }
                */
            }

            var info_el = top.getElement(".spt_info");
            spt.panel.load(info_el, class_name, values);
            spt.app_busy.hide();
            '''
        }

        # Save button
        button = ActionButtonWdg(title="Save", tip="Save Rule")
        td.add(button)
        button.add_style("float: right")
        behavior['mode'] = 'save'
        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''

            var top = bvr.src_el.getParent(".spt_ingestion_top");
            var values = spt.api.Utility.get_input_values(top, null, false);
            spt.app_busy.show("Saving ...");

            var class_name = 'tactic.command.CheckinRuleSaveCmd';
            var server = TacticServerStub.get();
            server.execute_cmd(class_name, values);

            spt.panel.refresh(top, {});

            spt.app_busy.hide();

            '''
        })

        # Scan button
        button = ActionButtonWdg(title="Scan", tip="Click to Scan")
        td.add(button)
        button.add_style("float: left")

        # set a limit
        #limit = TextWdg("limit")
        #td.add(limit)
        #text.add_style("float: left")

        behavior = behavior.copy()
        behavior['mode'] = 'scan'
        button.add_behavior(behavior)

        # Test button
        button = ActionButtonWdg(title="Test", tip="Do a test of this rule")
        td.add(button)
        behavior = behavior.copy()
        behavior['mode'] = 'test'
        button.add_behavior(behavior)
        button.add_style("float: left")

        # Ingest button
        button = ActionButtonWdg(title="Ingest",
                                 tip="Click to start ingesting")
        td.add(button)
        behavior = behavior.copy()
        behavior['mode'] = 'checkin'
        button.add_behavior(behavior)

        table.add_behavior({
            'type':
            'listen',
            'event_name':
            'file_browser|select',
            'cbjs_action':
            '''
            var dirname = bvr.firing_data.dirname;
            var top = bvr.src_el.getParent(".spt_ingestion_top");
            var kwargs = {
              base_dir: dirname
            };

            spt.panel.load(top, top.getAttribute("spt_class_name"), kwargs);
            '''
        })

        top.add(self.get_info_wdg())

        return top
Пример #5
0
    def get_display(self):

        top = self.top
        top.add_color("background", "background")
        top.add_class("spt_pipelines_top")
        self.set_as_panel(top)

        inner = DivWdg()
        top.add(inner)


        search_type = self.kwargs.get("search_type")
        pipeline_code = self.kwargs.get("pipeline_code")

        if search_type:
            search = Search("sthpw/pipeline")
            search.add_filter("search_type", search_type)
            pipelines = search.get_sobjects()
        else:
            pipeline = Pipeline.get_by_code(pipeline_code)
            if pipeline:
                pipelines = [pipeline]
            else:
                pipelines = []


        if not pipelines:
            div = DivWdg()
            inner.add(div)
            inner.add_style("padding: 50px")
            div.add_border()
            div.add_color("color", "color3")
            div.add_color("background", "background3")
            div.add_style("width: 400px")
            div.add_style("height: 100px")
            div.add_style("padding: 30px")
           
            icon = IconWdg("WARNING", IconWdg.WARNING)
            div.add(icon)
            div.add("<b>This Searchable Type does not have pipelines defined.</b>")
            div.add("<br/>"*2)

            div.add("<b style='padding-left: 35px'>Click Create to add one...</b>")
            div.add("<br/>"*2)
 
            button_div = DivWdg()
            div.add(button_div)

            button = ActionButtonWdg(title="Create", tip="Create pipeline")
            button_div.add(button)
            button.add_style("margin: auto")
            button.add_behavior( {
                'type': 'click_up',
                'search_type': search_type,
                'cbjs_action': '''
                var server = TacticServerStub.get();

                var cmd = 'tactic.ui.startup.PipelineCreateCbk';
                var kwargs = {
                    search_type: bvr.search_type
                }
                server.execute_cmd(cmd, kwargs)

                var top = bvr.src_el.getParent(".spt_pipelines_top");
                spt.panel.refresh(top);
                '''
            } )

            return top



        # get the defalt task statuses
        task_pipeline = Pipeline.get_by_code("task")
        if task_pipeline:
            statuses = task_pipeline.get_process_names()
        else:
            statuses = ['Pending', 'In Progress', 'Complete']
        statuses_str = ",".join(statuses)



        pipelines_div = DivWdg()
        inner.add( pipelines_div )
        pipelines_div.add_style("font-size: 12px")
        pipelines_div.add_style("padding: 10px")

        buttons_div = DivWdg()
        pipelines_div.add(buttons_div)

        #button = SingleButtonWdg( title="Save Pipelines", icon=IconWdg.SAVE )
        button = ActionButtonWdg( title="Save" )
        buttons_div.add(button)
        button.add_behavior( {
        'type': 'click_up',
        'default_statuses': statuses_str,
        'cbjs_action': '''
        spt.app_busy.show("Saving Pipeline...")

        setTimeout(function() {
            try {
                var top = bvr.src_el.getParent(".spt_pipelines_top");
                // get all the pipeline divs
                var pipeline_els = top.getElements(".spt_pipeline_top");
                var data = {};
                for ( var i = 0; i < pipeline_els.length; i++) {
                    var pipeline_code = pipeline_els[i].getAttribute("spt_pipeline_code");
                    var values = spt.api.Utility.get_input_values(pipeline_els[i]);
                    data[pipeline_code] = values;
                }


                var class_name = 'tactic.ui.startup.PipelineEditCbk';
                var kwargs = {
                    data: data
                }
                var server = TacticServerStub.get();
                server.execute_cmd(class_name, kwargs);
            } catch(e) {
                spt.alert(spt.exception.handler(e));
            }
            spt.app_busy.hide();
        }
        , 100);

        '''
        } )


        buttons_div.add("<br clear='all'/>")
        buttons_div.add_style("margin-bottom: 5px")




        for pipeline in pipelines:
            pipeline_div = DivWdg()
            pipelines_div.add(pipeline_div)
            pipeline_div.add_class("spt_pipeline_top")


            code = pipeline.get_code()
            label = '%s  (%s)' %(pipeline.get('name'), code)
            pipeline_div.add_attr("spt_pipeline_code", code)

            title = DivWdg()
            pipeline_div.add(title)
            title.add("Pipeline: ")
            
            title.add(label)
            title.add_style("padding: 8px 10px")
            title.add_color("background", "background3")
            title.add_style("font-weight: bold")
            title.add_style("margin: -10 -10 5 -10")


            header_wdg = DivWdg()
            pipeline_div.add(header_wdg)
            header_wdg.add_color("background", "background", -5)

            headers = ['Process', 'Description', 'Task Status']
            widths = ['100px', '180px', '210px']
            for header, width in zip(headers,widths):
                th = DivWdg()
                header_wdg.add(th)
                th.add("<b>%s</b>" % header)
                th.add_style("float: left")
                th.add_style("width: %s" % width)
                th.add_style("padding: 8px 3px")
            header_wdg.add("<br clear='all'/>")



            # get all of the process sobjects from this pipeline
            pipeline_code = pipeline.get_code()
            search = Search("config/process")
            search.add_filter("pipeline_code", pipeline.get_code() )
            process_sobjs = search.get_sobjects()

            process_sobj_dict = {}
            for process_sobj in process_sobjs:
                process = process_sobj.get_value("process")
                process_sobj_dict[process] = process_sobj


            from tactic.ui.container import DynamicListWdg
            dyn_list = DynamicListWdg()
            pipeline_div.add(dyn_list)
            pipeline_div.add_style("width: 725px")

            processes = pipeline.get_process_names()
            if not processes:
                processes.append("")
                processes.append("")
                processes.append("")

            processes.insert(0, "")

            for i, process in enumerate(processes):

                if process == '':
                    process_name = ''
                    description = ''
                else:
                    process_sobj = process_sobj_dict.get(process)
                    if process_sobj:
                        process_name = process_sobj.get_value("process")
                        description = process_sobj.get_value("description")
                    else:
                        if isinstance(process,basestring):
                            process_name = process
                        else:
                            process_name = process.get_name()
                        deccription = ''

                process_type = 'manual'
                process_xpos = ''
                process_ypos = ''
                # get the task pipeline for this process
                if process_name:
                    process = pipeline.get_process(process_name)
                    process_type = process.get_type()
                    process_xpos = process.get_attribute('xpos')
                    process_ypos = process.get_attribute('ypos')

                    task_pipeline_code = process.get_task_pipeline()
                    if task_pipeline_code != "task":
                        task_pipeline = Search.get_by_code("sthpw/pipeline", task_pipeline_code)
                    else:
                        task_pipeline = None
                else:
                    task_pipeline_code = "task"
                    task_pipeline = None

                
                process_div = DivWdg()
                process_div.add_style("float: left")
                process_div.add_class("spt_process_top")


                if i == 0:
                    dyn_list.add_template(process_div)
                else:
                    dyn_list.add_item(process_div)

                #process_div.add_style("padding-left: 10px")
                #process_div.add_style("margin: 5px")

                table = Table()
                process_div.add(table)
                table.add_row()

                text = TextInputWdg(name="process")
                process_cell = table.add_cell(text)
                text.add_style("width: 95px")
                text.add_style("margin: 5px")
                text.set_value(process_name)
                text.add_class("spt_process")

                # the template has a border
                if i == 0:
                    text.add_style("border: solid 1px #AAA")

                hidden = HiddenWdg(name='process_type')
                hidden.set_value(process_type)
                process_cell.add(hidden)

                hidden = HiddenWdg(name='process_xpos')
                hidden.set_value(process_xpos)
                process_cell.add(hidden)

                hidden = HiddenWdg(name='process_ypos')
                hidden.set_value(process_ypos)
                process_cell.add(hidden)


                text = TextInputWdg(name="description")
                table.add_cell(text)
                text.add_style("width: 175px")
                text.add_style("margin: 5px")
                text.set_value(description)
                # the template has a border
                if i == 0:
                    text.add_style("border: solid 1px #AAA")

                
                if process_type in ['manual','approval']:
                    read_only = False
                else:
                    read_only = True
                text = TextInputWdg(name="task_status", read_only=read_only)

                table.add_cell(text)
                text.add_style("width: 325px")
                text.add_style("margin: 5px")

                #text.set_value(statuses_str)
                    #text.add_style("opacity: 0.5")
                

                text.add_style("border-style: none")
                if process_type in ['manual','approval']:
                    if task_pipeline:
                        statuses = task_pipeline.get_process_names()
                        text.set_value(",".join(statuses))
                    else:
                        text.set_value("(default)")
                    text.add_behavior( {
                    'type': 'click_up',
                    'statuses': statuses_str,
                    'cbjs_action': '''
                    if (bvr.src_el.value == '(default)') {
                        bvr.src_el.value = bvr.statuses;
                    }
                    '''
                    } )

                table.add_cell("&nbsp;"*2)

                button = IconButtonWdg(tip="Trigger", icon=IconWdg.ARROW_OUT)
                table.add_cell(button)
                button.add_behavior( {
                    'type': 'click_up',
                    'search_type': search_type,
                    'pipeline_code': pipeline_code,
                    'cbjs_action': '''
                    var top = bvr.src_el.getParent(".spt_process_top");
                    var process_el = top.getElement(".spt_process");

                    var process = process_el.value;
                    if (process == "") {
                        alert("Process value is empty");
                        return;
                    }

                    var class_name = 'tactic.ui.tools.TriggerToolWdg';
                    var kwargs = {
                        mode: "pipeline",
                        process: process,
                        pipeline_code: bvr.pipeline_code
                    };
                    spt.panel.load_popup("Trigger", class_name, kwargs);
     
                    '''
                } )

                """
                button = IconButtonWdg(tip="Edit", icon=IconWdg.EDIT)
                table.add_cell(button)
                button.add_behavior( {
                    'type': 'click_up',
                    'search_type': search_type,
                    'pipeline_code': pipeline_code,
                    'cbjs_action': '''
                    var top = bvr.src_el.getParent(".spt_process_top");
                    var process_el = top.getElement(".spt_process");

                    var process = process_el.value;
                    if (process == "") {
                        alert("Process value is empty");
                        return;
                    }

                    var class_name = 'tactic.ui.panel.EditWdg';
                    var kwargs = {
                        expression: "@SOBJECT(config/process['process','"+process+"'])"
                    }
                    spt.panel.load_popup("Trigger", class_name, kwargs);
     
                    '''
                } )
                """

                table.add_cell("&nbsp;"*3)
               


            pipeline_div.add("<br clear='all'/>")
            pipeline_div.add("<br clear='all'/>")



        if self.kwargs.get("is_refresh"):
            return inner
        else:
            return top
Пример #6
0
    def get_display(my):

        data = my.kwargs.get('kwargs')
        if data:
            data = jsonloads(data)
            my.kwargs.update(data)

        my.search_type = my.kwargs.get("search_type")

        my.x_axis = my.kwargs.get("x_axis")
        if not my.x_axis:
            my.x_axis = 'code'

        my.y_axis = my.kwargs.get("y_axis")
        if type(my.y_axis) == types.ListType:
            my.y_axis = "|".join(my.y_axis)

        my.chart_type = my.kwargs.get("chart_type")
        if not my.chart_type:
            my.chart_type = 'bar'

        # get any search keys if any are passed in
        my.search_keys = my.kwargs.get("search_keys")

        top = DivWdg()
        top.add_class("spt_chart_builder")
        top.add_color("background", "background")
        top.add_border()

        from tactic.ui.app import HelpButtonWdg
        help_button = HelpButtonWdg(alias='charting')
        top.add(help_button)
        help_button.add_style("float: right")

        project = Project.get()
        search_types = project.get_search_types(include_sthpw=True)
        search_types = [x.get_value("search_type") for x in search_types]

        build_div = DivWdg()

        from pyasm.widget import SwapDisplayWdg
        swap_wdg = SwapDisplayWdg.get_triangle_wdg()
        swap_script = swap_wdg.get_swap_script()
        build_div.add(swap_wdg)

        build_div.add("<b>Chart Specifications</b>")
        build_div.add_style("margin-bottom: 5px")
        build_div.add_style("height: 25px")
        build_div.add_style("padding-top: 5px")
        build_div.add_gradient("background", "background", -10)
        build_div.add_color("color", "color")

        build_div.add_class("hand")
        build_div.add_class("SPT_DTS")
        top.add(build_div)
        build_div.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var top = bvr.src_el.getParent(".spt_chart_builder");
            var spec = top.getElement(".spt_chart_spec");
            //spt.api.toggle_show_hide(spec);
            spt.toggle_show_hide(spec);
            %s;
            ''' % swap_script
        })

        spec_div = DivWdg()
        spec_div.add_color("color", "color3")
        spec_div.add_color("background", "background3")
        spec_div.add_class("spt_chart_spec")
        spec_div.add_border()
        spec_div.add_style("padding: 10px")
        spec_div.add_style("margin: 5px")
        spec_div.add_style("display: none")
        top.add(spec_div)

        table = Table()
        table.add_color("color", "color3")
        spec_div.add(table)

        # add the search type selector
        table.add_row()
        table.add_cell("Search Type: ")

        search_type_div = DivWdg()
        search_type_select = TextWdg("search_type")
        search_type_select.set_value(my.search_type)
        #search_type_select.set_option("values", search_types)
        search_type_div.add(search_type_select)
        table.add_cell(search_type_div)

        # add the chart type selector
        table.add_row()
        table.add_cell("Chart Type: ")

        type_div = DivWdg()
        #type_div.add_style("padding: 3px")
        type_select = SelectWdg("chart_type")
        type_select.set_option("values", "line|bar|area")
        if my.chart_type:
            type_select.set_value(my.chart_type)
        type_div.add(type_select)
        table.add_cell(type_div)

        # add the chart type selector
        table.add_row()
        table.add_cell("X-Axis: ")

        # need to find all expression widgets or use get_text_value()?
        x_axis_div = DivWdg()
        x_axis_text = TextWdg("x_axis")
        x_axis_text.set_value("code")
        x_axis_div.add(x_axis_text)
        table.add_cell(x_axis_div)

        # add the chart type selector
        table.add_row()
        td = table.add_cell("Y-Axis: ")
        td.add_style("vertical-align: top")

        y_axis_div = DivWdg()
        #y_axis_text = TextWdg("y_axis")
        #if my.y_axis:
        #    y_axis_text.set_value(my.y_axis)
        #y_axis_div.add(y_axis_text)
        td = table.add_cell(y_axis_div)

        # add in a list of entries
        from tactic.ui.container import DynamicListWdg
        list_wdg = DynamicListWdg()
        for value in my.y_axis.split("|"):
            item = TextWdg("y_axis")
            item.set_value(value, set_form_value=False)
            list_wdg.add_item(item)
        y_axis_div.add(list_wdg)

        spec_div.add("<br/>")
        from tactic.ui.widget import ActionButtonWdg
        button = ActionButtonWdg(title="Refresh")
        spec_div.add(button)
        spec_div.add(HtmlElement.br(2))
        button.add_style("float: left")

        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
        var top = bvr.src_el.getParent(".spt_chart_builder");
        var chart = top.getElement(".spt_chart");
        var values = spt.api.get_input_values(top);
        //var values = spt.api.Utility.get_input_values(top);
        spt.panel.refresh(chart, values);
        '''
        })

        #TODO: provide a field for user to type in the chart name
        """

        button = ActionButtonWdg(title="Save")
        spec_div.add(button)
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_chart_builder");
        var chart = top.getElement(".spt_chart");
        var values = spt.api.get_input_values(top);

        var login = '******';
        var search_type = 'SideBarWdg';
        var side_bar_view = 'project_view';
        var unique_el_name = 'chart_test'

        var kwargs = {};
        kwargs['login'] = null;
        //if (save_as_personal) 
        //    kwargs['login'] = login;
        kwargs['class_name'] = 'tactic.ui.chart.ChartBuilderWdg';

        var display_options = {};
        display_options['search_type'] = 'prod/asset'
        kwargs['display_options'] = display_options;
 
        kwargs['unique'] = true;
        //if (new_title)
        //    kwargs['element_attrs'] = {'title': new_title}; 

        var server = TacticServerStub.get()
        server.add_config_element(search_type, side_bar_view, unique_el_name, kwargs);
        spt.panel.refresh("side_bar");
        '''
        } )
        """

        width = '600px'
        kwargs = {
            'y_axis': my.y_axis,
            'chart_type': my.chart_type,
            'search_type': my.search_type,
            'width': width,
            'search_keys': my.search_keys
        }

        chart_div = DivWdg()
        chart = BarChartWdg(**kwargs)

        chart_div.add(chart)
        top.add(chart_div)

        #from chart2_wdg import SampleSObjectChartWdg
        #chart = SampleSObjectChartWdg(**kwargs)
        #chart_div.add(chart)

        return top
Пример #7
0
    def get_display(my):

        top = my.top
        top.add_color("background", "background")
        top.add_class("spt_columns_top")
        my.set_as_panel(top)
        top.add_style("padding: 10px")

        search_type = my.kwargs.get("search_type")
        search_type_obj = SearchType.get(search_type)

        inner = DivWdg()
        top.add(inner)
        inner.add_style("width: 500px")

        #text = TextWdg("search_type")
        text = HiddenWdg("search_type")
        inner.add(text)
        text.set_value(search_type)

        title_wdg = DivWdg()
        inner.add(title_wdg)
        title_wdg.add( search_type_obj.get_title() )
        title_wdg.add(" <i style='font-size: 9px;opacity: 0.5'>(%s)</i>" % search_type)
        title_wdg.add_style("padding: 5px")
        title_wdg.add_color("background", "background3")
        title_wdg.add_color("color", "color3")
        title_wdg.add_style("margin: -10px -10px 10px -10px")
        title_wdg.add_style("font-weight: bold")





        shelf_wdg = DivWdg()
        inner.add(shelf_wdg)
        shelf_wdg.add_style("height: 30px")
        button = ActionButtonWdg(title='Create', icon=IconWdg.SAVE)
        shelf_wdg.add(button)
        shelf_wdg.add_style("float: right")




        button.add_behavior( {
            'type': 'click_up',
            'search_type': search_type,
            'cbjs_action': '''
            var class_name = 'tactic.ui.startup.ColumnEditCbk';
            var top = bvr.src_el.getParent(".spt_columns_top");

            var elements = top.getElements(".spt_columns_element");

            var values = [];
            for (var i = 0; i < elements.length; i++ ) {
                var data = spt.api.Utility.get_input_values(elements[i], null, false);
                values.push(data)
            }

            var kwargs = {
                search_type: bvr.search_type,
                values: values
            }


            var server = TacticServerStub.get();
            try {
                server.execute_cmd(class_name, kwargs);

                var names = [];
                for (var i = 0; i < values.length; i++) {
                    var name = values[i].name;
                    name = name.strip();
                    if (name == '') { continue; }
                    names.push(name);
                }

                spt.table.add_columns(names)

                // prevent grabbing all values, pass in a dummy one
                spt.panel.refresh(top, {'refresh': true});

            } catch(e) {
                spt.alert(spt.exception.handler(e));
            }

            '''
        } )
        

        # add the headers
        table = Table()
        inner.add(table)
        table.add_style("width: 100%")
        tr = table.add_row()
        tr.add_gradient("background", "background3")
        tr.add_style("padding", "3px")
        th = table.add_header("Column Name")
        th.add_style("width: 170px")
        th.add_style("text-align: left")
        th = table.add_header("Format")
        th.add_style("text-align: left")


        from tactic.ui.container import DynamicListWdg
        dyn_list = DynamicListWdg()
        inner.add(dyn_list)


        from tactic.ui.manager import FormatDefinitionEditWdg

        for i in range(0, 4):
            column_div = DivWdg()
            column_div.add_class("spt_columns_element")
            if i == 0:
                dyn_list.add_template(column_div)
            else:
                dyn_list.add_item(column_div)

            column_div.add_style("padding: 3px")
            column_div.add_style("float: left")

            table = Table()
            column_div.add(table)
            table.add_row()

            text_wdg = NewTextWdg("name")
            td = table.add_cell(text_wdg)
            text_wdg.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;
                '''
            } )

            option = {
            'name': 'xxx',
            'values': 'integer|float|percent|currency|date|time|scientific|boolean|text|timecode',
            }
            format_wdg = FormatDefinitionEditWdg(option=option)

            td = table.add_cell(format_wdg)
            td.add_style("width: 260px")
            td.add_style("padding-left: 40px")


        # show the current columns
        title_wdg = DivWdg()
        inner.add(title_wdg)
        title_wdg.add_style("margin-top: 20px")
        title_wdg.add("<b>Existing Columns</b>")
        title_wdg.add_color("background", "background3")
        title_wdg.add_style("padding: 5px")
        title_wdg.add_style("margin: 20px -10px 10px -10px")


        config = WidgetConfigView.get_by_search_type(search_type, "definition")
        element_names = config.get_element_names()

        table = Table()
        inner.add(table)
        table.add_style("width: 100%")

        tr = table.add_row()
        tr.add_gradient("background", "background3")
        th = table.add_header("Column")
        th.add_style("text-align: left")
        th = table.add_header("Data Type")
        th.add_style("text-align: left")
        th = table.add_header("Format")
        th.add_style("text-align: left")
        th = table.add_header("Edit")
        th.add_style("text-align: left")

        count = 0
        for element_name in element_names:
            display_class = config.get_display_handler(element_name)

            if display_class != 'tactic.ui.table.FormatElementWdg':
                continue

            table.add_row()

            display_options = config.get_display_options(element_name)
            format = display_options.get("format")
            if not format:
                format = '<i>text</i>'
            data_type = display_options.get("type")

            table.add_cell(element_name)
            table.add_cell(data_type)
            table.add_cell(format)

            td = table.add_cell()
            button = IconButtonWdg(title="Edit Definition", icon=IconWdg.EDIT)
            td.add(button)

            button.add_behavior( {
            'type': 'click_up',
            'search_type': search_type,
            'element_name': element_name,
            'cbjs_action': '''

            var class_name = 'tactic.ui.manager.ElementDefinitionWdg';
            var kwargs = {
                search_type: bvr.search_type,
                view: 'definition',
                element_name: bvr.element_name
            };
            spt.panel.load_popup("Element Definition", class_name, kwargs);
            '''
            } )

            count += 1


        if not count:
            table.add_row()
            td = table.add_cell()
            td.add_style("height: 50px")
            td.add("No existing columns found")
            td.add_style("text-align: center")
            td.add_border()
            td.add_color("background", "background", -5)





        if my.kwargs.get("is_refresh"):
            return inner
        else:
            return top
Пример #8
0
    def get_display(my):

        top = my.top
        top.add_color("background", "background")
        top.add_class("spt_columns_top")
        my.set_as_panel(top)
        top.add_style("padding: 10px")

        search_type = my.kwargs.get("search_type")
        search_type_obj = SearchType.get(search_type)

        inner = DivWdg()
        top.add(inner)
        inner.add_style("width: 500px")

        #text = TextWdg("search_type")
        text = HiddenWdg("search_type")
        inner.add(text)
        text.set_value(search_type)

        title_wdg = DivWdg()
        inner.add(title_wdg)
        title_wdg.add(search_type_obj.get_title())
        title_wdg.add(" <i style='font-size: 9px;opacity: 0.5'>(%s)</i>" %
                      search_type)
        title_wdg.add_style("padding: 5px")
        title_wdg.add_color("background", "background3")
        title_wdg.add_color("color", "color3")
        title_wdg.add_style("margin: -10px -10px 10px -10px")
        title_wdg.add_style("font-weight: bold")

        shelf_wdg = DivWdg()
        inner.add(shelf_wdg)
        shelf_wdg.add_style("height: 30px")
        button = ActionButtonWdg(title='Create', icon=IconWdg.SAVE)
        shelf_wdg.add(button)
        shelf_wdg.add_style("float: right")

        button.add_behavior({
            'type':
            'click_up',
            'search_type':
            search_type,
            'cbjs_action':
            '''
            var class_name = 'tactic.ui.startup.ColumnEditCbk';
            var top = bvr.src_el.getParent(".spt_columns_top");

            var elements = top.getElements(".spt_columns_element");

            var values = [];
            for (var i = 0; i < elements.length; i++ ) {
                var data = spt.api.Utility.get_input_values(elements[i], null, false);
                values.push(data)
            }

            var kwargs = {
                search_type: bvr.search_type,
                values: values
            }


            var server = TacticServerStub.get();
            try {
                server.execute_cmd(class_name, kwargs);

                var names = [];
                for (var i = 0; i < values.length; i++) {
                    var name = values[i].name;
                    name = name.strip();
                    if (name == '') { continue; }
                    names.push(name);
                }

                spt.table.add_columns(names)

                // prevent grabbing all values, pass in a dummy one
                spt.panel.refresh(top, {'refresh': true});

            } catch(e) {
                spt.alert(spt.exception.handler(e));
            }

            '''
        })

        # add the headers
        table = Table()
        inner.add(table)
        table.add_style("width: 100%")
        tr = table.add_row()
        tr.add_gradient("background", "background3")
        tr.add_style("padding", "3px")
        th = table.add_header("Column Name")
        th.add_style("width: 170px")
        th.add_style("text-align: left")
        th = table.add_header("Format")
        th.add_style("text-align: left")

        from tactic.ui.container import DynamicListWdg
        dyn_list = DynamicListWdg()
        inner.add(dyn_list)

        from tactic.ui.manager import FormatDefinitionEditWdg

        for i in range(0, 4):
            column_div = DivWdg()
            column_div.add_class("spt_columns_element")
            if i == 0:
                dyn_list.add_template(column_div)
            else:
                dyn_list.add_item(column_div)

            column_div.add_style("padding: 3px")
            column_div.add_style("float: left")

            table = Table()
            column_div.add(table)
            table.add_row()

            text_wdg = NewTextWdg("name")
            td = table.add_cell(text_wdg)
            text_wdg.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;
                '''
            })

            option = {
                'name':
                'xxx',
                'values':
                'integer|float|percent|currency|date|time|scientific|boolean|text|timecode',
            }
            format_wdg = FormatDefinitionEditWdg(option=option)

            td = table.add_cell(format_wdg)
            td.add_style("width: 260px")
            td.add_style("padding-left: 40px")

        # show the current columns
        title_wdg = DivWdg()
        inner.add(title_wdg)
        title_wdg.add_style("margin-top: 20px")
        title_wdg.add("<b>Existing Columns</b>")
        title_wdg.add_color("background", "background3")
        title_wdg.add_style("padding: 5px")
        title_wdg.add_style("margin: 20px -10px 10px -10px")

        config = WidgetConfigView.get_by_search_type(search_type, "definition")
        element_names = config.get_element_names()

        table = Table()
        inner.add(table)
        table.add_style("width: 100%")

        tr = table.add_row()
        tr.add_gradient("background", "background3")
        th = table.add_header("Column")
        th.add_style("text-align: left")
        th = table.add_header("Data Type")
        th.add_style("text-align: left")
        th = table.add_header("Format")
        th.add_style("text-align: left")
        th = table.add_header("Edit")
        th.add_style("text-align: left")

        count = 0
        for element_name in element_names:
            display_class = config.get_display_handler(element_name)

            if display_class != 'tactic.ui.table.FormatElementWdg':
                continue

            table.add_row()

            display_options = config.get_display_options(element_name)
            format = display_options.get("format")
            if not format:
                format = '<i>text</i>'
            data_type = display_options.get("type")

            table.add_cell(element_name)
            table.add_cell(data_type)
            table.add_cell(format)

            td = table.add_cell()
            button = IconButtonWdg(title="Edit Definition", icon=IconWdg.EDIT)
            td.add(button)

            button.add_behavior({
                'type':
                'click_up',
                'search_type':
                search_type,
                'element_name':
                element_name,
                'cbjs_action':
                '''

            var class_name = 'tactic.ui.manager.ElementDefinitionWdg';
            var kwargs = {
                search_type: bvr.search_type,
                view: 'definition',
                element_name: bvr.element_name
            };
            spt.panel.load_popup("Element Definition", class_name, kwargs);
            '''
            })

            count += 1

        if not count:
            table.add_row()
            td = table.add_cell()
            td.add_style("height: 50px")
            td.add("No existing columns found")
            td.add_style("text-align: center")
            td.add_border()
            td.add_color("background", "background", -5)

        if my.kwargs.get("is_refresh"):
            return inner
        else:
            return top