Esempio n. 1
0
    def execute(self):

        self.base_dir = self.kwargs.get("base_dir")
        if not self.base_dir:
            self.base_dir = Environment.get_template_dir()


        self.project_code = self.kwargs.get("project_code")
        if not self.project_code:
            self.project_code = Project.get_project_code()

        assert self.project_code

        # project code can be called anything, and we want to have a _template suffix for the template code
        #self.plugin_code = "%s_template" % self.project_code

        #self.template_project_code = re.sub( '_template$', '', self.plugin_code)
        self.template_project_code = self.project_code
        self.project = Project.get_by_code(self.project_code)
        if not self.project:
            raise TacticException('This project [%s] does not exist'%self.project_code)

        self.project_type = self.project.get_value("type")
        if not self.project_type:
            self.project_type = self.project_code
        Project.set_project(self.project_code)

        self.export_template()
Esempio n. 2
0
    def execute(my):

        my.base_dir = my.kwargs.get("base_dir")
        if not my.base_dir:
            my.base_dir = Environment.get_template_dir()


        my.project_code = my.kwargs.get("project_code")
        if not my.project_code:
            my.project_code = Project.get_project_code()

        assert my.project_code

        # project code can be called anything, and we want to have a _template suffix for the template code
        #my.plugin_code = "%s_template" % my.project_code

        #my.template_project_code = re.sub( '_template$', '', my.plugin_code)
        my.template_project_code = my.project_code
        my.project = Project.get_by_code(my.project_code)
        if not my.project:
            raise TacticException('This project [%s] does not exist'%my.project_code)

        my.project_type = my.project.get_value("type")
        if not my.project_type:
            my.project_type = my.project_code
        Project.set_project(my.project_code)

        my.export_template()
Esempio n. 3
0
    def execute(my):

        from pyasm.common import ZipUtil
        ziputil = ZipUtil()

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

        upload_dir = Environment.get_upload_dir()
        template_dir = Environment.get_template_dir()

        for path in paths:
            path = path.replace("\\", "/")
            basename = os.path.basename(path)
            upload_path = "%s/%s" % (upload_dir, basename)

            if not upload_path.endswith(".zip"):
                continue

            print "upload: ", upload_path
            if not os.path.exists(upload_path):
                continue


            print "template_dir: ", template_dir
            shutil.move(upload_path, template_dir)
            to_path = "%s/%s" % (template_dir, basename)

            # unzip the file
            ziputil.extract(to_path)
Esempio n. 4
0
    def execute(self):

        from pyasm.common import ZipUtil
        ziputil = ZipUtil()

        paths = self.kwargs.get("paths")

        upload_dir = Environment.get_upload_dir()
        template_dir = Environment.get_template_dir()

        for path in paths:
            path = path.replace("\\", "/")
            basename = os.path.basename(path)
            upload_path = "%s/%s" % (upload_dir, basename)

            if not upload_path.endswith(".zip"):
                continue

            print "upload: ", upload_path
            if not os.path.exists(upload_path):
                continue


            print "template_dir: ", template_dir
            shutil.move(upload_path, template_dir)
            to_path = "%s/%s" % (template_dir, basename)

            # unzip the file
            ziputil.extract(to_path)
Esempio n. 5
0
    def execute(self):

        self.base_dir = self.kwargs.get("base_dir")
        if not self.base_dir:
            self.base_dir = Environment.get_template_dir()

        self.project_code = self.kwargs.get("project_code")
        if not self.project_code:
            self.project_code = Project.get_project_code()

        assert self.project_code

        # project code can be called anything, and we want to have a _template suffix for the template code
        #self.plugin_code = "%s_template" % self.project_code

        #self.template_project_code = re.sub( '_template$', '', self.plugin_code)
        self.template_project_code = self.project_code
        self.project = Project.get_by_code(self.project_code)
        if not self.project:
            raise TacticException('This project [%s] does not exist' %
                                  self.project_code)

        self.project_type = self.project.get_value("type")
        if not self.project_type:
            self.project_type = self.project_code
        Project.set_project(self.project_code)

        self.export_template()
Esempio n. 6
0
    def handle_path(my, src_path):

        src_path = src_path.replace("\\", "/")

        # upload folder
        basename = os.path.basename(src_path)

        if my.mode =='copy':
            target_path = src_path
            target_dir = os.path.dirname(target_path)
        else:
            target_dir = Environment.get_upload_dir()
            target_path = "%s/%s" % (target_dir, basename)
    

        base_dir = Environment.get_template_dir()
        template_dir = "%s/%s" % (base_dir, my.project_code)
        

        if os.path.exists(template_dir):
            shutil.rmtree(template_dir)
            #raise TacticException("Template is already installed at [%s]" %template_dir)

        # unzip the file
        from pyasm.common import ZipUtil
        # this is fixed for windows if zipping doesn't use compression
        paths = ZipUtil.extract(target_path)

        # veryify that the paths extracted are the expected ones
        rootname, ext = os.path.splitext(basename)

        # check if it unzips at the templates folder directly
        unzip_at_template_dir = False
        # move the plugin zip file to the appropriate folder
        if my.mode == 'copy':
            # if they manually drop the zip file already here, skip
            if target_dir != base_dir:
                shutil.copy(target_path, base_dir)
            else:
                unzip_at_template_dir = True
        else:
            shutil.move(target_path, base_dir)


        # move unzipped files into the plugin area
        # remove any version info, only allow 1 particular version installed for now
        import re
        rootname = re.sub('(.*)(-)(\d.*)', r'\1', rootname)
        unzip_path = "%s/%s" % (target_dir, rootname)
       
        
        dest_dir = '%s/%s'%(base_dir, rootname)
        
        if not unzip_at_template_dir and os.path.exists(dest_dir):
            shutil.rmtree(dest_dir)

            shutil.move(unzip_path, dest_dir)
Esempio n. 7
0
    def get_display(self):

        div = DivWdg()
        div.add_class("spt_project_template_top")
        self.set_as_panel(div)

        div.add_color("background", "background")

        upload_div = DivWdg()
        upload_div.add_style("padding: 10px")
        upload_div.add_style("width: 600px")



        # add the main layout
        table = ResizableTableWdg()
        table.add_color("color", "color")
        div.add(table)

        table.add_row()
        left = table.add_cell()
        left.add_border()
        left.add_style("min-width: 250px")
        left.add_style("height: 400px")

        left.add(self.get_templates_wdg() )

        right = table.add_cell()
        right.add_border()
        right.add_style("width: 400px")
        right.add_style("height: 400px")
        right.add_style("padding: 5px")
        right.add_class("spt_project_template_content")

        template = self.kwargs.get("template")
        if template: 
            template_dir = Environment.get_template_dir()
            template_dir = "%s/%s" % (template_dir, template)
            class_name = 'tactic.ui.app.ProjectTemplateEditWdg';
            content_div = ProjectTemplateEditWdg(template_dir=template_dir)
        else:
            content_div = DivWdg()
            content_div.add_style("margin: 40px")
            content_div.add_style("width: 300px")
            content_div.add_style("height: 150px")
            content_div.add_style("opacity: 0.7")
            content_div.add_border()
            content_div.add_color("background", "background3")
            content_div.add("<br/>"*4)
            content_div.add("No templates selected")
            content_div.add_style("text-align: center")

        right.add(content_div)

        return div
Esempio n. 8
0
    def get_display(my):

        div = DivWdg()
        div.add_class("spt_project_template_top")
        my.set_as_panel(div)

        div.add_color("background", "background")

        upload_div = DivWdg()
        upload_div.add_style("padding: 10px")
        upload_div.add_style("width: 600px")



        # add the main layout
        table = ResizableTableWdg()
        table.add_color("color", "color")
        div.add(table)

        table.add_row()
        left = table.add_cell()
        left.add_border()
        left.add_style("min-width: 250px")
        left.add_style("height: 400px")

        left.add(my.get_templates_wdg() )

        right = table.add_cell()
        right.add_border()
        right.add_style("width: 400px")
        right.add_style("height: 400px")
        right.add_style("padding: 5px")
        right.add_class("spt_project_template_content")

        template = my.kwargs.get("template")
        if template: 
            template_dir = Environment.get_template_dir()
            template_dir = "%s/%s" % (template_dir, template)
            class_name = 'tactic.ui.app.ProjectTemplateEditWdg';
            content_div = ProjectTemplateEditWdg(template_dir=template_dir)
        else:
            content_div = DivWdg()
            content_div.add_style("margin: 40px")
            content_div.add_style("width: 300px")
            content_div.add_style("height: 150px")
            content_div.add_style("opacity: 0.7")
            content_div.add_border()
            content_div.add_color("background", "background3")
            content_div.add("<br/>"*4)
            content_div.add("No templates selected")
            content_div.add_style("text-align: center")

        right.add(content_div)

        return div
Esempio n. 9
0
    def execute(my):
        template = my.kwargs.get("template")

        template_dir = Environment.get_template_dir()

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


        from pyasm.search import FileUndo
        path = "%s/%s-1.0.0.zip" % (template_dir, template)
        if not os.path.exists(path):
            raise Exception("Path [%s] does not exists" % path)

        FileUndo.remove(path)

        path = "%s/%s" % (template_dir, template)
        FileUndo.remove(path)
Esempio n. 10
0
    def execute(self):
        template = self.kwargs.get("template")

        template_dir = Environment.get_template_dir()

        template = self.kwargs.get("template")


        from pyasm.search import FileUndo
        path = "%s/%s-1.0.0.zip" % (template_dir, template)
        if not os.path.exists(path):
            raise Exception("Path [%s] does not exists" % path)

        FileUndo.remove(path)

        path = "%s/%s" % (template_dir, template)
        FileUndo.remove(path)
Esempio n. 11
0
    def execute(my):

        template_dir = Environment.get_template_dir()

        # find the 
        template_dir = my.kwargs.get("template_dir")
        if not template_dir:
            return


        path = None

        template_name = os.path.basename(template_dir)
        template_dir = os.path.dirname(template_dir)

        filenames = os.listdir(template_dir)
        for filename in filenames:
            if not filename.endswith(".zip"):
                continue

            if filename.startswith(template_name):
                path = "%s/%s" % (template_dir, filename)
                break

        if not path:
            return


        asset_dir = Environment.get_asset_dir()

        ticket = Environment.get_ticket()
        cache_dir = "%s/_cache/%s" % (asset_dir, ticket)

        if not os.path.exists(cache_dir):
            os.makedirs(cache_dir)

        shutil.copy(path, cache_dir)

        my.info["filename"] = filename
Esempio n. 12
0
    def execute(self):

        template_dir = Environment.get_template_dir()

        # find the 
        template_dir = self.kwargs.get("template_dir")
        if not template_dir:
            return


        path = None

        template_name = os.path.basename(template_dir)
        template_dir = os.path.dirname(template_dir)

        filenames = os.listdir(template_dir)
        for filename in filenames:
            if not filename.endswith(".zip"):
                continue

            if filename.startswith(template_name):
                path = "%s/%s" % (template_dir, filename)
                break

        if not path:
            return


        asset_dir = Environment.get_asset_dir()

        ticket = Environment.get_ticket()
        cache_dir = "%s/_cache/%s" % (asset_dir, ticket)

        if not os.path.exists(cache_dir):
            os.makedirs(cache_dir)

        shutil.copy(path, cache_dir)

        self.info["filename"] = filename
Esempio n. 13
0
    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> &nbsp;&nbsp;")
    
        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: &nbsp;&nbsp;</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)" % ("&nbsp;"*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: &nbsp;&nbsp;</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>&nbsp; ")
        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
Esempio n. 14
0
    def get_templates_wdg(my):

        div = DivWdg()
        div.add_style("padding: 5px")
        div.add_color("background", "background3")
        div.add_style("height: 100%")

        title_div = DivWdg()

        button = ActionButtonWdg(title="+", tip="Choose a Project Template file to install", size="small")
        title_div.add(button)
        button.add_style("float: right")
        button.add_style("margin-top: -6px")
        button.add_style("margin-right: -4px")
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': r'''
            var applet = spt.Applet.get();
            spt.app_busy.show('Choose a Project Template file');

            var paths = applet.open_file_browser();
            var server = TacticServerStub.get();
            var cmd = "tactic.ui.app.ProjectTemplateInstallCmd";

            if (!paths.length) {
                return;
            }

            try {
                
                for (var i = 0; i < paths.length; i++) {    
                    if (!paths[i].test(/\.zip/)) {
                        spt.alert('A template file should be a zip file');
                        return;
                    }

                    server.upload_file(paths[i]);
                }

                var kwargs = {
                    paths: paths
                };
                server.execute_cmd(cmd, kwargs);

                var path = paths[0]
                path = path.replace(/\\/g, "/");
                var parts = path.split("/");
                var name = parts[parts.length-1];
                var parts2 = name.split("-");
                var name = parts2[0];


                var top = bvr.src_el.getParent(".spt_project_template_top");
                top.setAttribute("spt_template", name);
                spt.panel.refresh(top);
                spt.app_busy.hide();
                spt.notify.show_message("Project Template ["+name+"] has been installed.");
            }catch (e) {
                spt.app_busy.hide();
                spt.alert(spt.exception.handler(e));
            }

            '''
        } )




        div.add(title_div)
        title_div.add("<b>Installed Templates</b>")
        title_div.add_gradient("background", "background", 0, -10)
        title_div.add_color("color", "color3")
        title_div.add_style("margin: -5px -5px 5px -5px")
        title_div.add_style("font-weight: bold")
        title_div.add_style("padding: 8px")

        templates_div = DivWdg()
        div.add(templates_div)

        templates_div.add_relay_behavior( {
            'type': 'mouseup',
            'bvr_match_class': 'spt_template',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_project_template_top");
            var content = top.getElement(".spt_project_template_content")
            var class_name = 'tactic.ui.app.ProjectTemplateEditWdg';
            var template_dir = bvr.src_el.getAttribute("spt_template_dir");
            var kwargs = {
                template_dir: template_dir
            };
            spt.panel.load(content, class_name, kwargs);
            '''
        } )
        templates_div.add_class("hand")


        bgcolor = title_div.get_color("background3")
        bgcolor2 = title_div.get_color("background3", -10)
        templates_div.add_relay_behavior( {
            'type': 'mouseover',
            'bvr_match_class': 'spt_template',
            'cbjs_action': '''
            bvr.src_el.setStyle("background", "%s")
            ''' % bgcolor2
        } )
        templates_div.add_relay_behavior( {
            'type': 'mouseout',
            'bvr_match_class': 'spt_template',
            'cbjs_action': '''
            bvr.src_el.setStyle("background", "%s")
            ''' % bgcolor
        } )





        template_dir = Environment.get_template_dir()
        if not template_dir:
            raise Exception("No template dir defined")
        #template_dir = "/home/apache/project_templates"
        dirnames = os.listdir(template_dir)

        #templates = ['scrum', 'tickets', 'vfx', 'game']
        for template in dirnames:

            path = "%s/%s" % (template_dir, template)

            if not os.path.isdir(path):
                continue


            template_div = DivWdg()
            templates_div.add(template_div)
            icon = IconWdg("View Template [%s]" % template, IconWdg.DETAILS)
            template_div.add(icon)
            template_div.add(template)
            template_div.add_style("padding: 5px 3px 5px 3px")
            template_div.add_class("spt_template")
            template_div.add_attr("spt_template_dir", path)

        return div
Esempio n. 15
0
    def import_template(my):

        if my.path:
            base_dir = os.path.dirname(my.path)
        else:
            base_dir = Environment.get_template_dir()

        version = my.kwargs.get("version")
        if version:
            template_dir = "%s/%s-%s" % (base_dir, my.template_code, version)
        else:
            template_dir = "%s/%s" % (base_dir, my.template_code)

        template_dir = my.get_template_dir(template_dir)

        # if the directory does not exist then look for a zip file
        use_zip = False
        if not os.path.exists(template_dir):
            template_zip = "%s.zip" % (template_dir)
            if os.path.exists(template_zip):
                use_zip = True
            else:
                hint = "Please check if you have created the Template already using the Update button in the Template Project view."
                if version:
                    raise TacticException(
                        "No template found for [%s] version [%s]. %s" %
                        (my.template_code, version, hint))
                else:
                    raise TacticException("No template found for [%s]. %s" %
                                          (my.template_code, hint))

        # check to see if the database exists in the default
        # database implementation
        from pyasm.search import DbContainer, DatabaseImpl
        impl = DatabaseImpl.get()
        exists = impl.database_exists(my.project_code)

        # if the database already exists, then raise an exception
        if exists and my.new_project:
            msg = "WARNING: Database [%s] already exists" % my.project_code
            print msg
            raise TacticException(msg)

        # this is the overriding factor:
        if my.is_template == True:
            title = Common.get_display_title(my.project_code)
        elif my.is_template == False:
            title = Common.get_display_title(my.project_code)
        elif my.is_template == None:
            # these 2 is for old usage using the command line script create_template.py
            if my.template_project_code != my.project_code:
                my.is_template = False
                title = Common.get_display_title(my.project_code)
            else:
                my.is_template = True
                title = Common.get_display_title(my.template_project_code)

        # create a new project if this was desired
        if my.new_project == True:
            from create_project_cmd import CreateProjectCmd
            project_image_path = my.kwargs.get("project_image_path")

            # the project_type will get updated properly by the PluginInstaller
            # but that break the ties to the project_type entry created though,
            # which is ok
            creator = CreateProjectCmd(project_code=my.project_code,
                                       project_title=title,
                                       project_type=my.template_project_code,
                                       is_template=my.is_template,
                                       use_default_side_bar=False,
                                       project_image_path=project_image_path)
            creator.execute()

        # set the project
        Project.set_project(my.project_code)

        # import from a plugin
        if use_zip:
            kwargs = {'zip_path': template_zip, 'code': my.project_code}

        else:
            kwargs = {'plugin_dir': template_dir}

        kwargs['filter_line_handler'] = my.filter_line_handler
        kwargs['filter_sobject_handler'] = my.filter_sobject_handler

        from plugin import PluginCreator, PluginInstaller
        installer = PluginInstaller(**kwargs)
        installer.execute()
Esempio n. 16
0
    def get_templates_wdg(self):

        div = DivWdg()
        div.add_style("padding: 5px")
        div.add_color("background", "background3")
        div.add_style("height: 100%")

        title_div = DivWdg()

        button = ActionButtonWdg(title="+", tip="Choose a Project Template file to install", size="small")
        title_div.add(button)
        button.add_style("float: right")
        button.add_style("margin-top: -6px")
        button.add_style("margin-right: -4px")
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': r'''
            var applet = spt.Applet.get();
            spt.app_busy.show('Choose a Project Template file');

            var paths = applet.open_file_browser();
            var server = TacticServerStub.get();
            var cmd = "tactic.ui.app.ProjectTemplateInstallCmd";

            if (!paths.length) {
                return;
            }

            try {
                
                for (var i = 0; i < paths.length; i++) {    
                    if (!paths[i].test(/\.zip/)) {
                        spt.alert('A template file should be a zip file');
                        return;
                    }

                    server.upload_file(paths[i]);
                }

                var kwargs = {
                    paths: paths
                };
                server.execute_cmd(cmd, kwargs);

                var path = paths[0]
                path = path.replace(/\\/g, "/");
                var parts = path.split("/");
                var name = parts[parts.length-1];
                var parts2 = name.split("-");
                var name = parts2[0];


                var top = bvr.src_el.getParent(".spt_project_template_top");
                top.setAttribute("spt_template", name);
                spt.panel.refresh(top);
                spt.app_busy.hide();
                spt.notify.show_message("Project Template ["+name+"] has been installed.");
            }catch (e) {
                spt.app_busy.hide();
                spt.alert(spt.exception.handler(e));
            }

            '''
        } )




        div.add(title_div)
        title_div.add("<b>Installed Templates</b>")
        title_div.add_gradient("background", "background", 0, -10)
        title_div.add_color("color", "color3")
        title_div.add_style("margin: -5px -5px 5px -5px")
        title_div.add_style("font-weight: bold")
        title_div.add_style("padding: 8px")

        templates_div = DivWdg()
        div.add(templates_div)

        templates_div.add_relay_behavior( {
            'type': 'mouseup',
            'bvr_match_class': 'spt_template',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_project_template_top");
            var content = top.getElement(".spt_project_template_content")
            var class_name = 'tactic.ui.app.ProjectTemplateEditWdg';
            var template_dir = bvr.src_el.getAttribute("spt_template_dir");
            var kwargs = {
                template_dir: template_dir
            };
            spt.panel.load(content, class_name, kwargs);
            '''
        } )
        templates_div.add_class("hand")


        bgcolor = title_div.get_color("background3")
        bgcolor2 = title_div.get_color("background3", -10)
        templates_div.add_relay_behavior( {
            'type': 'mouseover',
            'bvr_match_class': 'spt_template',
            'cbjs_action': '''
            bvr.src_el.setStyle("background", "%s")
            ''' % bgcolor2
        } )
        templates_div.add_relay_behavior( {
            'type': 'mouseout',
            'bvr_match_class': 'spt_template',
            'cbjs_action': '''
            bvr.src_el.setStyle("background", "%s")
            ''' % bgcolor
        } )





        template_dir = Environment.get_template_dir()
        if not template_dir:
            raise Exception("No template dir defined")
        #template_dir = "/home/apache/project_templates"
        dirnames = os.listdir(template_dir)

        #templates = ['scrum', 'tickets', 'vfx', 'game']
        for template in dirnames:

            path = "%s/%s" % (template_dir, template)

            if not os.path.isdir(path):
                continue


            template_div = DivWdg()
            templates_div.add(template_div)
            icon = IconWdg("View Template [%s]" % template, IconWdg.DETAILS)
            template_div.add(icon)
            template_div.add(template)
            template_div.add_style("padding: 5px 3px 5px 3px")
            template_div.add_class("spt_template")
            template_div.add_attr("spt_template_dir", path)

        return div
Esempio n. 17
0
    def import_template(my):

        if my.path:
            base_dir = os.path.dirname(my.path)
        else:
            base_dir = Environment.get_template_dir()


        version = my.kwargs.get("version")
        if version:
            template_dir = "%s/%s-%s" % (base_dir, my.template_code, version)
        else:
            template_dir = "%s/%s" % (base_dir, my.template_code)

        template_dir = my.get_template_dir(template_dir)
        
        # if the directory does not exist then look for a zip file
        use_zip = False
        if not os.path.exists(template_dir):
            template_zip = "%s.zip" % (template_dir)
            if os.path.exists(template_zip):
                use_zip = True
            else:
                hint = "Please check if you have created the Template already using the Update button in the Template Project view."
                if version:
                    raise TacticException("No template found for [%s] version [%s]. %s" % (my.template_code, version, hint))
                else:
                    raise TacticException("No template found for [%s]. %s" % (my.template_code, hint))
                    



        # check to see if the database exists in the default
        # database implementation
        from pyasm.search import DbContainer, DatabaseImpl
        impl = DatabaseImpl.get()
        exists = impl.database_exists(my.project_code)

        # if the database already exists, then raise an exception
        if exists and my.new_project:
            msg = "WARNING: Database [%s] already exists" % my.project_code
            print msg
            raise TacticException(msg)


        # this is the overriding factor:
        if my.is_template == True:
            title = Common.get_display_title(my.project_code)
        elif my.is_template == False:
            title = Common.get_display_title(my.project_code)
        elif my.is_template == None:
            # these 2 is for old usage using the command line script create_template.py
            if my.template_project_code != my.project_code:
                my.is_template = False
                title = Common.get_display_title(my.project_code)
            else:
                my.is_template = True
                title = Common.get_display_title(my.template_project_code)


        # create a new project if this was desired
        if my.new_project == True:
            from create_project_cmd import CreateProjectCmd
            project_image_path = my.kwargs.get("project_image_path")

            # the project_type will get updated properly by the PluginInstaller
            # but that break the ties to the project_type entry created though,
            # which is ok
            creator = CreateProjectCmd(
                project_code=my.project_code,
                project_title=title,
                project_type=my.template_project_code,
                is_template=my.is_template,
                use_default_side_bar=False,
                project_image_path=project_image_path
            )
            creator.execute()


        # set the project
        Project.set_project(my.project_code)

        # import from a plugin
        if use_zip:
            kwargs = {
                'zip_path': template_zip,
                'code': my.project_code
            }

        else:
            kwargs = {
                'plugin_dir': template_dir
            }


        kwargs['filter_line_handler'] = my.filter_line_handler
        kwargs['filter_sobject_handler'] = my.filter_sobject_handler

        from plugin import PluginCreator, PluginInstaller
        installer = PluginInstaller( **kwargs )
        installer.execute()