Example #1
0
    def _test_access_level(my):
        security = Environment.get_security()
        from pyasm.security import get_security_version
        security_version = get_security_version()


        projects = Search.eval('@SOBJECT(sthpw/project)')
        if security_version >= 2:
            for project in projects:
                key = { "code": project.get_code() }
                key2 = { "code": "*" }
                keys = [key, key2]
                default = "deny"
                # other than sample3d, unittest as allowed above, a default low access level user 
                # should not see other projects
                access = security.check_access("project", keys, "allow", default=default)
                process_keys = [{'process': 'anim'}]
                proc_access = security.check_access("process", process_keys, "allow")
                my.assertEquals(proc_access, True)
                if project.get_code() in ['sample3d','unittest']:
                    my.assertEquals(access, True)
                else:
                    my.assertEquals(access, False)
        else:
            raise SecurityException('Please test with security version 2. Set it in your config file')
Example #2
0
    def set_project(cls, project_code):
        '''This is kept here because everybody is used to using this'''

        security = Environment.get_security()
        # FIXME:
        # Because it is possible to call this before one is
        # logged in.  This is required to see the login screen.
        from pyasm.security import get_security_version
        security_version = get_security_version()
        if security_version != 1 and not project_code == 'admin':
            key = {'code': project_code}
            key2 = {'code': "*"}
            keys = [key, key2]
            if not security.check_access(
                    "project", keys, access="allow", default="deny"):
                user = Environment.get_login()
                if user:
                    user = user.get_value("login")
                    raise SecurityException(
                        "User [%s] is not permitted to view project [%s]" %
                        (user, project_code))
                else:
                    raise SecurityException(
                        "Not permitted to view project [%s]" % (project_code))

        from pyasm.security import Site
        site = Site.get_site()
        PROJECT_KEY = "Project:global:%s:" % site
        Container.put(PROJECT_KEY, project_code)
Example #3
0
    def set_project(cls, project_code):
        '''This is kept here because everybody is used to using this'''

        security = Environment.get_security()
        # FIXME:
        # Because it is possible to call this before one is 
        # logged in.  This is required to see the login screen.
        from pyasm.security import get_security_version
        security_version = get_security_version()
        if security_version != 1 and not project_code == 'admin':
            key = { 'code': project_code }
            key2 = { 'code': "*" }
            keys = [key, key2]
            if not security.check_access("project", keys, access="allow", default="deny"):
                user = Environment.get_login()
                if user:
                    user = user.get_value("login")
                    raise SecurityException("User [%s] is not permitted to view project [%s]" % (user, project_code))
                else:
                    raise SecurityException("User is not permitted to view project [%s]" % (project_code))

        from pyasm.security import Site
        site = Site.get_site()
        PROJECT_KEY = "Project:global:%s:" % site
        Container.put(PROJECT_KEY, project_code)
Example #4
0
    def _test_access_level(my):
        security = Environment.get_security()
        from pyasm.security import get_security_version
        security_version = get_security_version()


        projects = Search.eval('@SOBJECT(sthpw/project)')
        if security_version >= 2:
            for project in projects:
                key = { "code": project.get_code() }
                key2 = { "code": "*" }
                keys = [key, key2]
                default = "deny"
                # other than sample3d, unittest as allowed above, a default low access level user 
                # should not see other projects
                access = security.check_access("project", keys, "allow", default=default)
                process_keys = [{'process': 'anim'}]
                proc_access = security.check_access("process", process_keys, "allow")
                my.assertEquals(proc_access, True)
                if project.get_code() in ['sample3d','unittest']:
                    my.assertEquals(access, True)
                else:
                    my.assertEquals(access, False)
        else:
            raise SecurityException('Please test with security version 2. Set it in your config file')
Example #5
0
    def get_display(my):

        menus = []

        widget = DivWdg(id='ProjectSelectWdg', css='spt_panel')
        widget.set_attr('spt_class_name', 'tactic.ui.app.ProjectSelectWdg') 
        if not WebContainer.get_web().is_IE():
            widget.add_style("float: right")

        from tactic.ui.widget import SingleButtonWdg
        button = SingleButtonWdg(title='Open Project', icon=IconWdg.PROJECT, show_arrow=True)
        widget.add(button)


        #from tactic.ui.activator import ButtonForDropdownMenuWdg
        #menu_data = []
        #menu_id = "project_select_menu"

        allowed = Project.get_user_projects()
        allowed_codes = [x.get_code() for x in allowed]

        search = Search("sthpw/project")
        search.add_filters("code", allowed_codes)
        # ignore some builtin projects
        search.add_where("\"code\" not in ('admin','sthpw','unittest')")
        search.add_op("begin")
        #search.add_filter("is_template", 'true', quoted=False, op='!=')
        search.add_filter("is_template", True, op='!=')
        search.add_filter("is_template", 'NULL', quoted=False, op='is')
        search.add_op("or")
        projects = search.get_sobjects()


        from tactic.ui.container import  Menu, MenuItem
        menu = Menu(width=240)
        menus.append(menu)
        menu.set_allow_icons(False)

        security = Environment.get_security()
        if security.check_access("builtin", "view_site_admin", "allow", default="deny") or security.check_access("builtin", "create_projects", "allow", default="deny"):
            menu_item = MenuItem(type='title', label='Project Action')
            menu.add(menu_item)

            menu_item = MenuItem(type='action', label='Create New Project')
            menu.add(menu_item)
            menu_item.add_behavior( {
            'cbjs_action': '''
            //spt.popup.open('create_project_wizard');
            //Effects.fade_in($('create_project_wizard'), 200);
            var env = spt.Environment.get();
            var project = env.get_project();
            if (project == 'admin') {
                spt.tab.set_main_body_top();
                var class_name = 'tactic.ui.app.ProjectCreateWdg';
                spt.tab.add_new("create_project", "Create Project", class_name);
            }
            else {
                document.location = "/tactic/admin/link/create_project";
            }
            '''
            } )


            search = Search("config/url")
            search.add_filter("url", "/index")
            url = search.get_sobject()
            if url:
                menu_item = MenuItem(type='action', label='Open Index')
                menu.add(menu_item)
                menu_item.add_behavior( {
                'cbjs_action': '''
                var env = spt.Environment.get();
                var project = env.get_project();
                //document.location = "/tactic/" + project + "/";
                window.open('/tactic/'+project+'/');
                '''
                } )




        menu_item = MenuItem(type='title', label='Open Project')
        menu.add(menu_item)


        def add_project_menu(menu, project):
            project_code = project.get_code()
            menu_item = MenuItem(type='action', label=project.get_value("title"))

            web = WebContainer.get_web()
            browser = web.get_browser()

            if browser != 'Qt':

                menu_item.add_behavior( {
                'type': 'click_up',
                'project_code': project_code,
                'cbjs_action': '''
                window.open('/tactic/%s/');
                ''' % project_code
                } )

            else:
                menu_item.add_behavior( {
                'project_code': project_code,
                'cbjs_action': '''
                spt.app_busy.show("Jumping to Project ["+bvr.project_code+"]", "");
                document.location = '/tactic/%s/';
                ''' % project_code
                } )

            menu.add(menu_item)


        search = Search("sthpw/project")
        search.add_column("category", distinct=True)
        categories = [x.get_value("category") for x in search.get_sobjects() ]
        for category in categories:
            if category == '':
                continue

            # FIXME: a little inefficient, but should be ok for now
            category_projects = []
            for project in projects:
                if project.get_value("category") != category:
                    continue

                project_code = project.get_code()
                if not security.check_access("project", project_code, "view"):
                    continue
                
                category_projects.append(project)

            if category_projects:
                suffix = Common.get_filesystem_name(category)
                label = "%s (%s)" % (category, len(category_projects))
                menu_item = MenuItem(type='submenu', label=label)
                menu_item.set_submenu_tag_suffix(suffix)
                menu.add(menu_item)

                submenu = Menu(width=200, menu_tag_suffix=suffix)
                menus.append(submenu)
                for project in category_projects:
                    add_project_menu(submenu, project)


        from pyasm.security import get_security_version
        security_version = get_security_version()

        for project in projects:
            if project.get_value("category") != "":
                continue

            project_code = project.get_code()
            if security_version >= 2:
                key = { "code": project_code }
                key2 = { "code": "*" }
                keys = [key, key2]
                default = "deny"
                if not security.check_access("project", keys, "allow", default=default):
                    continue
            else:
                if not security.check_access("project", project_code, "view", default="allow"):
                    continue

            add_project_menu(menu, project)



        if not projects:
            menu_item = MenuItem(type='action', label="- No Projects Created -")
            menu_item.add_behavior( {
            'cbjs_action': '''
            '''
            } )
            menu.add(menu_item)




        if security.check_access("builtin", "view_site_admin", "allow") or security.check_access("builtin", "view_template_projects", "allow"):
            search = Search("sthpw/project")
            #search.add_filter("is_template", 'true', quoted=False)
            search.add_filter("is_template", True)
            projects = search.get_sobjects()

            if projects:
                menu_item = MenuItem(type='title', label="Template Projects")
                menu.add(menu_item)

           

            for project in projects:
                project_code = project.get_code()
                if security_version >= 2:
                    key = { "code": project_code }
                    key2 = { "code": "*" }
                    keys = [key, key2]
                    default = "deny"
                    if not security.check_access("project", keys, "allow", default=default):
                        continue
                else:
                    if not security.check_access("project", project_code, "view", default="allow"):
                        continue

                menu_item = MenuItem(type='action', label=project.get_value("title"))
                menu_item.add_behavior( {
                'project_code': project_code,
                'cbjs_action': '''
                spt.app_busy.show("Jumping to Project ["+bvr.project_code+"]", "");
                document.location = '/projects/%s/'
                ''' % project_code
                } )
                menu.add(menu_item)


        if security.check_access("builtin", "view_site_admin", "allow", default="deny") or security.check_access("builtin", "create_projects", "allow", default="deny"):
            menu_item = MenuItem(type='title', label="Admin")
            menu.add(menu_item)
            project = Project.get_by_code("admin")
            add_project_menu(menu, project)





        from tactic.ui.container import SmartMenu
        smenu_set = SmartMenu.add_smart_menu_set( button, { 'BUTTON_MENU': menus } )
        SmartMenu.assign_as_local_activator( button, "BUTTON_MENU", True )


        return widget
Example #6
0
    def get_display(self):

        top = DivWdg()
        top.add_border()
        top.add_style("padding: 10px")
        top.add_color("color", "color")
        top.add_color("background", "background")
        #top.add_style("height: 550px")

        top.add_class("spt_reports_top")


        title = DivWdg()
        title.add("Searchable Lists")
        title.add_style("font-size: 18px")
        title.add_style("font-weight: bold")
        title.add_style("text-align: center")
        title.add_style("padding: 10px")
        title.add_style("margin: -10px -10px 0px -10px")

        top.add(title)
        title.add_gradient("background", "background3", 5, -10)
        top.add("<br/>")

        button_div = DivWdg()
        top.add(button_div)
        button = SingleButtonWdg(title="Collapse", icon=IconWdg.ARROW_UP)
        button_div.add(button)
        top.add(button_div)
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_reports_top");
            var element = top.getElement(".spt_reports_list");
            spt.toggle_show_hide(element)

            '''
        } )

        #desc = DivWdg()
        #top.add(desc)
        #desc.add("Dashboard")
        #desc.add_style("width: 600px")

        reports = []

        # read the config file
        """
        from pyasm.widget import WidgetConfig
        tmp_path = __file__
        dir_name = os.path.dirname(tmp_path)
        file_path="%s/../config/reports-conf.xml" % (dir_name)
        config = WidgetConfig.get(file_path=file_path, view="definition")
        element_names = config.get_element_names()

        for element_name in element_names:
            print "element_name: ", element_name
            attrs = config.get_element_attributes(element_name)
            report_data = {}
            kwargs = config.get_display_options(element_name)
            class_name = kwargs.get('class_name')

            report_data['class_name'] = class_name
            report_data['kwargs'] = kwargs
            report_data['title'] = attrs.get("title")
            report_data['description'] = attrs.get("description")

            reports.append(report_data)
        """

        project = Project.get()
        project_code = project.get_code()
        search_type_objs = project.get_search_types()

        filtered = [] 
        for search_type_obj in search_type_objs:
            search_type = search_type_obj.get_value("search_type")

            # FIXME: this code is also present 
            from pyasm.security import get_security_version
            security_version = get_security_version()
            if security_version >= 2 and not search_type.startswith("sthpw/") and not search_type.startswith("config/"):
                security = Environment.get_security()

                table = search_type_obj.get_value("table_name")

                default = "deny"
                key  = { "element": "%s_list" % table }
                key2 = { "element": "%s_list" % table, "project": project_code }
                key3 = { "element": "*" }
                key4 = { "element": "*", "project": project_code }
                keys = [key, key2, key3, key4]
                if not security.check_access("link", keys, "view", default=default):
                    continue

                key = { "code": search_type }
                key2 = { "code": "*" }
                keys = [key, key2]
                if not security.check_access("search_type", keys, "view", default=default):
                    continue
                

                filtered.append(search_type_obj)


        search_type_objs = filtered

        for search_type_sobj in search_type_objs:
            description = search_type_sobj.get_value("description")
            search_type = search_type_sobj.get_value("search_type")



            search = Search(search_type)
            count = search.get_count()

            title_div = DivWdg()
            items_div = DivWdg()
            title_div.add(items_div)
            items_div.add_style("font-size: 9px")
            items_div.add_style("font-weight: italic")
            items_div.add_style("float: right")
            items_div.add("%s item/s" % count)
            title_div.add(search_type_sobj.get_title())

            description_div = DivWdg()
            description_div.add(description)
            description_div.add_style("padding: 5px")
            if not description:
                description_div.add("<br/>(No description)")
                description_div.add_style("font-style: italic")
                description_div.add_style("opacity: 0.3")


            report_data = {
                'title': search_type_sobj.get_title(),
                'title_wdg': title_div,
                'class_name': 'tactic.ui.panel.ViewPanelWdg',
                'kwargs': {
                        'search_type': search_type,
                        'view': 'table',
                        'simple_search_view': 'simple_search'
                    },
                'description': description_div,
                'search_type': search_type_sobj
            }
            reports.append(report_data)


        # create a bunch of panels
        list_div = DivWdg()
        top.add(list_div)
        list_div.add_class("spt_reports_list")


        table = Table()
        list_div.add(table)
        table.add_color("color", "color")
        table.add_style("margin-bottom: 5px")
        table.center()

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


        for i, report in enumerate(reports):

            if i == 0 or i%4 == 0:
                tr = table.add_row()

            td = table.add_cell()
            td.add_style("vertical-align: top")
            td.add_style("padding: 3px")

            class_name = report.get("class_name")
            kwargs = report.get("kwargs")
            title = report.get("title")
            description = report.get("description")

            #image = "<img src='/context/images/getting_started_schema.png'/>"
            image = "<img src='/context/images/getting_started_pipeline.png'/>"


            thumb_div = DivWdg()
            image = thumb_div
            thumb_div.add_border()
            thumb_div.set_box_shadow("1px 1px 1px 1px")

            thumb = ThumbWdg()
            thumb_div.add(thumb)
            thumb.set_sobject(report.get("search_type"))
            thumb.set_icon_size(60)




            behavior = {
            'type': 'click_up',
            'title': title,
            'class_name': class_name,
            'kwargs': kwargs,
            'cbjs_action': '''

            var top = bvr.src_el.getParent(".spt_reports_top");
            //spt.tab.set_main_body_tab();
            spt.tab.set_tab_top(top);
            var kwargs = {};
            spt.tab.add_new(bvr.title, bvr.title, bvr.class_name, bvr.kwargs);
            '''
            }
            title_wdg = report.get("title_wdg")
            schema_wdg = self.get_section_wdg(title_wdg, description, image, behavior)
            td.add(schema_wdg)



        from tactic.ui.container import TabWdg
        tab = TabWdg(show_add=False)
        top.add(tab)



        return top
Example #7
0
    def get_display(self):

        web = WebContainer.get_web()
        palette = web.get_palette()

        widget = DivWdg()
        widget.add_style("width: 100%")
        widget.add_style("text-align: center")

        from tactic.ui.app import PageHeaderWdg
        header = PageHeaderWdg(show_project=False)
        widget.add(header)

        security = Environment.get_security()

        search = Search("sthpw/project")
        search.add_where("\"code\" not in ('sthpw', 'admin', 'unittest')")
        search.add_where("\"type\" not in ('resource')")
        # hide template projects
        if security.check_access("builtin", "view_site_admin",
                                 "allow") or security.check_access(
                                     "builtin", "view_template_projects",
                                     "allow"):
            pass
        else:
            search.add_op("begin")
            search.add_filter("is_template", True, op='!=')
            search.add_filter("is_template", 'NULL', quoted=False, op='is')
            search.add_op("or")

        search.add_order_by("category")

        projects = search.get_sobjects()

        num = len(projects)
        # sort by project
        if num < 5:
            columns = 1
            icon_size = 90
            width = 500
        elif num < 15:
            columns = 2
            icon_size = 60
            width = 700
        else:
            columns = 3
            icon_size = 45
            width = 800

        div = DivWdg()

        div.add_style("margin-left: auto")
        div.add_style("margin-right: auto")
        #div.add_style("width: 520px")
        div.center()
        widget.add(div)

        #logo = TacticLogoWdg()
        #div.add(logo)
        div.add("<br/>" * 3)

        bg_color = palette.color("background")
        #div.add_color("color", "color")

        from tactic.ui.container import RoundedCornerDivWdg
        div = RoundedCornerDivWdg(hex_color_code=bg_color, corner_size="10")
        div.set_dimensions(width_str='%spx' % width, content_height_str='50px')
        div.add_border()
        div.add_style("overflow: hidden")
        div.set_box_shadow()

        div.add_style("margin-left: auto")
        div.add_style("margin-right: auto")
        div.add_style("width: %spx" % width)
        table = Table()
        table.set_max_width()
        table.add_style("margin-left: auto")
        table.add_style("margin-right: auto")
        table.add_style("background-color: %s" % bg_color)
        table.add_color("color", "color")

        tr, td = table.add_row_cell()
        logo_div = DivWdg()
        logo_div.add_gradient("background", "background3", -5, -10)
        td.add(logo_div)
        logo = TacticLogoWdg()
        logo_div.add(logo)
        logo_div.add_style("margin: -6 -6 6 -6")

        app_name = WebContainer.get_web().get_app_name()
        security = Environment.get_security()

        last_category = None
        has_category = False
        index = 0

        # if TACTIC has not been set up, show the configuration page
        # FIXME: what is the requirement for is_installed?
        config_path = Config.get_config_path()
        if not os.path.exists(config_path):
            is_installed = False
        else:
            is_installed = True
        #is_installed = True

        # filter out projects due to security
        filtered = []
        for i, project in enumerate(projects):

            from pyasm.security import get_security_version
            security_version = get_security_version()
            if security_version >= 2:
                key = {"code": project.get_code()}
                key2 = {"code": "*"}
                keys = [key, key2]
                default = "deny"
                if not security.check_access(
                        "project", keys, "allow", default=default):
                    continue
            else:

                if not security.check_access(
                        "project", project.get_code(), "view",
                        default="allow"):
                    continue

            filtered.append(project)

        projects = filtered

        if not is_installed:
            tr, td = table.add_row_cell()

            #from tactic.ui.startup import DbConfigWdg
            #td.add(DbConfigWdg())

            title_div = DivWdg()
            td.add(title_div)
            title_div.add_style("padding: 5px")
            title_div.add_style("font-weight: bold")
            title_div.add("Getting Started ...")
            title_div.add_gradient("background", "background", -10)

            projects_div = DivWdg()
            projects_div.add_style("padding: 20px")
            td.add(projects_div)
            projects_div.add_style("text-align: center")
            projects_div.add("Welcome to TACTIC ...<br/>")
            projects_div.add_style("font-size: 22px")

            msg_div = DivWdg()
            td.add(msg_div)
            msg_div.add(
                "Configure TACTIC to connect to an external database and set up asset folders.<br/><br/>"
            )
            msg_div.add_style("text-align: center")

            action = ActionButtonWdg(title='Confgure', size='medium')
            action.add_style("margin-left: auto")
            action.add_style("margin-right: auto")
            td.add(action)
            action.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
            document.location = "/tactic/admin/#/link/configure";
            '''
            })

            msg_div = DivWdg()
            td.add(msg_div)
            msg_div.add(
                "<br/><br/>Or start using TACTIC with default configuration with an internal database.<br/><br/>"
            )

            msg_div.add_style("text-align: center")
            action = ActionButtonWdg(title='Start >>', size='medium')
            action.add_style("margin-left: auto")
            action.add_style("margin-right: auto")
            td.add(action)
            action.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
            document.location = "/tactic";
            '''
            })

            msg_div = DivWdg()
            td.add(msg_div)
            msg_div.add("<br/><br/><br/>")
            msg_div.add_style("text-align: center")

        elif projects:
            num_projets = 0
            for i, project in enumerate(projects):

                category = project.get_value("category")
                if category is not None and category != last_category:

                    table.add_row()
                    tr, td = table.add_row_cell()
                    category_div = DivWdg()
                    td.add(category_div)
                    if has_category and not category:
                        category_div.add("&nbsp;")
                    else:
                        category_div.add(category)
                    category_div.add_style("padding: 8px")
                    category_div.add_style("font-size: 16px")
                    category_div.add_style("font-weight: bold")
                    category_div.add_color("color", "color")
                    category_div.add_gradient("background", "background3", 0,
                                              -10)
                    category_div.add_color("color", "color3")
                    #category_div.set_round_corners()
                    if last_category == None:
                        category_div.add_style("margin: -6 -6 6 -6")
                    else:
                        category_div.add_style("margin: 15 -6 0 -6")
                    table.add_row()
                    has_category = True
                    index = 0

                index += 1
                last_category = category

                thumb = ThumbWdg()
                thumb.set_name("snapshot")
                thumb.set_sobject(project)
                thumb.set_show_clipboard(False)
                thumb.set_has_img_link(False)
                thumb.set_icon_size(icon_size)

                code = project.get_code()
                title = project.get_value("title")
                # Restrict the length of project name
                if len(title) >= 36:
                    title = title[:36] + "..."
                if app_name != 'Browser':
                    href = HtmlElement.href(HtmlElement.h2(title), ref='/tactic/%s/%s'\
                        %(code, app_name))
                    img_href = HtmlElement.href(thumb, ref='/tactic/%s/%s'\
                        %(code, app_name))

                    link = '/tactic/%s/%s' % (code, app_name)
                else:
                    href = HtmlElement.href(HtmlElement.h2(title),
                                            ref="/tactic/%s/" % code)
                    img_href = DivWdg(thumb)
                    img_href.add_behavior({
                        'type':
                        'click_up',
                        'code':
                        code,
                        'cbjs_action':
                        '''
                        document.location = '/tactic/'+bvr.code+'/';
                        '''
                    })

                    link = '/tactic/%s/' % code

                href = href.get_buffer_display()
                if (index - 1) % columns == 0:
                    table.add_row()

                td = table.add_cell()
                img_div = DivWdg()
                img_div.add(img_href)
                img_div.add_style("margin-right: 20px")
                img_div.add_style("float: left")
                img_div.add_border()
                #img_div.set_round_corners()
                img_div.set_box_shadow("0px 1px 5px")

                project_div = DivWdg()
                td.add(project_div)
                td.add_style("width: 230px")
                project_div.add_style("font-size: 16px")
                project_div.add_style("font-weight: bold")
                project_div.add_style("vertical-align: middle")
                project_div.add(img_div)
                #project_div.add(href)
                project_div.add(title)
                if project.get_value("is_template") == True:
                    project_div.add(
                        "<br/><i style='opacity: 0.5; font-size: 12px'>(template)</i>"
                    )
                project_div.add_style("height: %spx" % (icon_size - 10))

                project_div.add_style("padding: 8px 10px 2px 20px")

                project_div.add_color("background", "background")
                project_div.add_behavior({
                    'type':
                    'hover',
                    'add_color_modifier':
                    -3,
                    'cb_set_prefix':
                    'spt.mouse.table_layout_hover',
                })
                project_div.set_round_corners()
                project_div.add_class("hand")

                project_div.add_behavior({
                    'type':
                    'click_up',
                    'link':
                    link,
                    'title':
                    title,
                    'cbjs_action':
                    '''
                document.location = bvr.link;
                '''
                })

        elif not security.check_access(
                "builtin", "view_site_admin", "allow",
                default="deny") and not security.check_access(
                    "builtin", "create_projects", "allow", default="deny"):
            tr, td = table.add_row_cell()

            msg_div = DivWdg()
            td.add(msg_div)
            from pyasm.widget import IconWdg
            icon = IconWdg("WARNING", IconWdg.WARNING)
            msg_div.add(icon)
            msg_div.add("You are not permitted to view any projects")
            msg_div.add_style("font-size: 16px")
            msg_div.add_style("text-align: center")
            msg_div.add_style("font-weight: bold")
            msg_div.add_style("margin: 50px")
            msg_div.add("<br/>" * 2)
            msg_div.add("Please click to Sign Out:<br/>")
            action = ActionButtonWdg(title='Sign Out >>', size='m')
            msg_div.add(action)
            action.add_style('margin: 5px auto')
            action.add_style('text-align: center')
            web = WebContainer.get_web()
            action.add_behavior({
                'type':
                'click_up',
                'login':
                web.get_user_name(),
                'cbjs_action':
                '''
                var server = TacticServerStub.get();
                server.execute_cmd("SignOutCmd", {login: bvr.login} );
                window.location.href='/';
                '''
            })

        else:
            tr, td = table.add_row_cell()

            title_div = DivWdg()
            td.add(title_div)
            title_div.add_style("padding: 10px")
            title_div.add_style("margin: -8px -6px 20px -6px")
            title_div.add_style("font-weight: bold")
            title_div.add("Getting Started ...")
            title_div.add_gradient("background", "background", -10)

            projects_div = DivWdg()
            projects_div.add_style("padding: 20px")
            td.add(projects_div)
            projects_div.add_style("text-align: center")
            projects_div.add("No Projects have been created ...<br/><br/>")
            projects_div.add_style("font-size: 22px")

            action = ActionButtonWdg(title='Create Project >>', size='large')
            action.add_style("margin-left: auto")
            action.add_style("margin-right: auto")
            projects_div.add(action)
            action.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
            document.location = "/tactic/admin/link/create_project";
            '''
            })

        if security.check_access("builtin", "view_site_admin", "allow"):
            admin_div = DivWdg()
            #href = HtmlElement.href(HtmlElement.h2('Admin Site'), ref='/tactic/admin/')
            #admin_div.add(href)
            #admin_div.add_border()
            admin_div.add_style("font-size: 16px")
            admin_div.add_style("font-weight: bold")
            admin_div.add_style("height: 30px")

            link_div = DivWdg()
            link_div.add_class("hand")
            admin_div.add(link_div)
            link_div.add("Go to Admin Site")
            link_div.add_style("text-align: center")
            link_div.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
            document.location = '/tactic/admin/';
            '''
            })
            tr, td = table.add_row_cell()
            td.add("<hr/><br/>")
            td.add(admin_div)

        div.add(table)
        widget.add(div)
        # Note sure what this is for
        #BaseAppServer.add_onload_script('spt.first_load=false')
        div.add_behavior({
            'type': 'load',
            'cbjs_action': '''spt.first_load=false'''
        })
        return widget
Example #8
0
    def get_display(self):


        web = WebContainer.get_web()
        palette = web.get_palette()

        widget = DivWdg()
        widget.add_style("width: 100%")
        widget.add_style("text-align: center")

        from tactic.ui.app import PageHeaderWdg
        header = PageHeaderWdg(show_project=False)
        widget.add( header )

        security = Environment.get_security()


        search = Search("sthpw/project")
        search.add_where("\"code\" not in ('sthpw', 'admin', 'unittest')")
        search.add_where("\"type\" not in ('resource')")
        # hide template projects
        if security.check_access("builtin", "view_site_admin", "allow") or security.check_access("builtin", "view_template_projects", "allow"):
            pass
        else:
            search.add_op("begin")
            search.add_filter("is_template", True, op='!=')
            search.add_filter("is_template", 'NULL', quoted=False, op='is')
            search.add_op("or")

        search.add_order_by("category")

        projects = search.get_sobjects()
        
        num = len(projects)
        # sort by project
        if num < 5:
            columns = 1
            icon_size = 90
            width = 500
        elif num < 15:
            columns = 2
            icon_size = 60
            width = 700
        else:
            columns = 3
            icon_size = 45
            width = 800

        div = DivWdg()

        div.add_style("margin-left: auto")
        div.add_style("margin-right: auto")
        #div.add_style("width: 520px")
        div.center()
        widget.add(div)

        #logo = TacticLogoWdg()
        #div.add(logo)
        div.add("<br/>"*3)

        bg_color = palette.color("background")
        #div.add_color("color", "color")

        from tactic.ui.container import RoundedCornerDivWdg
        div = RoundedCornerDivWdg(hex_color_code=bg_color,corner_size="10")
        div.set_dimensions( width_str='%spx' % width, content_height_str='50px' )
        div.add_border()
        div.add_style("overflow: hidden")
        div.set_box_shadow()

        div.add_style("margin-left: auto")
        div.add_style("margin-right: auto")
        div.add_style("width: %spx" % width)
        table = Table()
        table.set_max_width()
        table.add_style("margin-left: auto")
        table.add_style("margin-right: auto")
        table.add_style("background-color: %s" % bg_color)
        table.add_color("color", "color")

        tr, td = table.add_row_cell()
        logo_div = DivWdg()
        logo_div.add_gradient("background", "background3", -5, -10)
        td.add(logo_div)
        logo = TacticLogoWdg()
        logo_div.add(logo)
        logo_div.add_style("margin: -6 -6 6 -6")


        app_name = WebContainer.get_web().get_app_name()
        security = Environment.get_security() 

        last_category = None
        has_category = False
        index = 0 

        # if TACTIC has not been set up, show the configuration page
        # FIXME: what is the requirement for is_installed?
        config_path = Config.get_config_path()
        if not os.path.exists(config_path):
            is_installed = False
        else:
            is_installed = True
        #is_installed = True



        # filter out projects due to security
        filtered = []
        for i, project in enumerate(projects):

            from pyasm.security import get_security_version
            security_version = get_security_version()
            if security_version >= 2:
                key = { "code": project.get_code() }
                key2 = { "code": "*" }
                keys = [key, key2]
                default = "deny"
                if not security.check_access("project", keys, "allow", default=default):
                    continue
            else:

                if not security.check_access("project", project.get_code(), "view", default="allow"):
                    continue

            filtered.append(project)

        projects = filtered





        if not is_installed:
            tr, td = table.add_row_cell()

            #from tactic.ui.startup import DbConfigWdg
            #td.add(DbConfigWdg())

            title_div = DivWdg()
            td.add(title_div)
            title_div.add_style("padding: 5px")
            title_div.add_style("font-weight: bold")
            title_div.add("Getting Started ...")
            title_div.add_gradient("background", "background", -10)

            projects_div = DivWdg()
            projects_div.add_style("padding: 20px")
            td.add(projects_div)
            projects_div.add_style("text-align: center")
            projects_div.add("Welcome to TACTIC ...<br/>")
            projects_div.add_style("font-size: 22px")


            msg_div = DivWdg()
            td.add(msg_div)
            msg_div.add("Configure TACTIC to connect to an external database and set up asset folders.<br/><br/>")
            msg_div.add_style("text-align: center")


            action = ActionButtonWdg(title='Confgure', size='medium')
            action.add_style("margin-left: auto")
            action.add_style("margin-right: auto")
            td.add(action)
            action.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            document.location = "/tactic/admin/#/link/configure";
            '''
            } )


            msg_div = DivWdg()
            td.add(msg_div)
            msg_div.add("<br/><br/>Or start using TACTIC with default configuration with an internal database.<br/><br/>")

            msg_div.add_style("text-align: center")
            action = ActionButtonWdg(title='Start >>', size='medium')
            action.add_style("margin-left: auto")
            action.add_style("margin-right: auto")
            td.add(action)
            action.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            document.location = "/tactic";
            '''
            } )


            msg_div = DivWdg()
            td.add(msg_div)
            msg_div.add("<br/><br/><br/>")
            msg_div.add_style("text-align: center")



        elif projects:
            num_projets = 0
            for i, project in enumerate(projects):

                category = project.get_value("category")
                if category is not None and category != last_category:

                    table.add_row()
                    tr, td = table.add_row_cell()
                    category_div = DivWdg()
                    td.add(category_div)
                    if has_category and not category:
                        category_div.add("&nbsp;")
                    else:
                        category_div.add(category)
                    category_div.add_style("padding: 8px")
                    category_div.add_style("font-size: 16px")
                    category_div.add_style("font-weight: bold")
                    category_div.add_color("color", "color")
                    category_div.add_gradient("background", "background3",0, -10)
                    category_div.add_color("color", "color3")
                    #category_div.set_round_corners()
                    if last_category == None:
                        category_div.add_style("margin: -6 -6 6 -6")
                    else:
                        category_div.add_style("margin: 15 -6 0 -6")
                    table.add_row()
                    has_category = True
                    index = 0

                index += 1
                last_category = category


                thumb = ThumbWdg()
                thumb.set_name("snapshot")
                thumb.set_sobject(project)
                thumb.set_show_clipboard(False)
                thumb.set_has_img_link(False)
                thumb.set_icon_size(icon_size)
             
                code = project.get_code()
                title = project.get_value("title")
                # Restrict the length of project name
                if len(title) >= 36:
                    title = title[:36] + "..."
                if app_name != 'Browser':
                    href = HtmlElement.href(HtmlElement.h2(title), ref='/tactic/%s/%s'\
                        %(code, app_name))
                    img_href = HtmlElement.href(thumb, ref='/tactic/%s/%s'\
                        %(code, app_name))

                    link = '/tactic/%s/%s' % (code, app_name)
                else:
                    href = HtmlElement.href(HtmlElement.h2(title), ref="/tactic/%s/" % code)
                    img_href = DivWdg(thumb)
                    img_href.add_behavior( {
                        'type': 'click_up',
                        'code': code,
                        'cbjs_action': '''
                        document.location = '/tactic/'+bvr.code+'/';
                        '''
                    } )
                
                    link = '/tactic/%s/' % code

                href = href.get_buffer_display()
                if (index-1) % columns == 0:
                    table.add_row()
               
                td = table.add_cell()
                img_div = DivWdg()
                img_div.add(img_href)
                img_div.add_style("margin-right: 20px")
                img_div.add_style("float: left")
                img_div.add_border()
                #img_div.set_round_corners()
                img_div.set_box_shadow("0px 1px 5px")

                project_div = DivWdg()
                td.add(project_div)
                td.add_style("width: 230px")
                project_div.add_style("font-size: 16px")
                project_div.add_style("font-weight: bold")
                project_div.add_style("vertical-align: middle")
                project_div.add(img_div)
                #project_div.add(href)
                project_div.add(title)
                if project.get_value("is_template") == True:
                    project_div.add("<br/><i style='opacity: 0.5; font-size: 12px'>(template)</i>")
                project_div.add_style("height: %spx" % (icon_size-10))

                project_div.add_style("padding: 8px 10px 2px 20px")
                
                project_div.add_color("background", "background")
                project_div.add_behavior( {
                'type': 'hover',
                'add_color_modifier': -3,
                'cb_set_prefix': 'spt.mouse.table_layout_hover',
                } )
                project_div.set_round_corners()
                project_div.add_class("hand")

                project_div.add_behavior( {
                'type': 'click_up',
                'link': link,
                'title': title,
                'cbjs_action': '''
                document.location = bvr.link;
                '''
                } )

        elif not security.check_access("builtin", "view_site_admin", "allow", default="deny") and not security.check_access("builtin", "create_projects", "allow", default="deny"):
            tr, td = table.add_row_cell()

            msg_div = DivWdg()
            td.add(msg_div)
            from pyasm.widget import IconWdg
            icon = IconWdg("WARNING", IconWdg.WARNING)
            msg_div.add(icon)
            msg_div.add("You are not permitted to view any projects")
            msg_div.add_style("font-size: 16px")
            msg_div.add_style("text-align: center")
            msg_div.add_style("font-weight: bold")
            msg_div.add_style("margin: 50px")
            msg_div.add("<br/>"*2)
            msg_div.add("Please click to Sign Out:<br/>")
            action = ActionButtonWdg(title='Sign Out >>', size='m')
            msg_div.add(action)
            action.add_style('margin: 5px auto')
            action.add_style('text-align: center')
            web = WebContainer.get_web()
            action.add_behavior( {
                'type': 'click_up',
                'login': web.get_user_name(),
                'cbjs_action': '''
                var server = TacticServerStub.get();
                server.execute_cmd("SignOutCmd", {login: bvr.login} );
                window.location.href='/';
                '''
            } )

        else:
            tr, td = table.add_row_cell()

            title_div = DivWdg()
            td.add(title_div)
            title_div.add_style("padding: 10px")
            title_div.add_style("margin: -8px -6px 20px -6px")
            title_div.add_style("font-weight: bold")
            title_div.add("Getting Started ...")
            title_div.add_gradient("background", "background", -10)

            projects_div = DivWdg()
            projects_div.add_style("padding: 20px")
            td.add(projects_div)
            projects_div.add_style("text-align: center")
            projects_div.add("No Projects have been created ...<br/><br/>")
            projects_div.add_style("font-size: 22px")

            action = ActionButtonWdg(title='Create Project >>', size='large')
            action.add_style("margin-left: auto")
            action.add_style("margin-right: auto")
            projects_div.add(action)
            action.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            document.location = "/tactic/admin/link/create_project";
            '''
            } )


        if security.check_access("builtin", "view_site_admin", "allow"):
            admin_div = DivWdg()
            #href = HtmlElement.href(HtmlElement.h2('Admin Site'), ref='/tactic/admin/')
            #admin_div.add(href)
            #admin_div.add_border()
            admin_div.add_style("font-size: 16px")
            admin_div.add_style("font-weight: bold")
            admin_div.add_style("height: 30px")

            link_div = DivWdg()
            link_div.add_class("hand")
            admin_div.add(link_div)
            link_div.add("Go to Admin Site")
            link_div.add_style("text-align: center")
            link_div.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            document.location = '/tactic/admin/';
            '''
            } )
            tr, td = table.add_row_cell()
            td.add("<hr/><br/>")
            td.add(admin_div)


        div.add(table)
        widget.add(div)
        # Note sure what this is for
        #BaseAppServer.add_onload_script('spt.first_load=false')
        div.add_behavior( {
            'type': 'load',
            'cbjs_action': '''spt.first_load=false'''
        } )
        return widget
Example #9
0
    def get_display(my):

        top = DivWdg()
        top.add_border()
        top.add_style("padding: 10px")
        top.add_color("color", "color")
        top.add_color("background", "background")
        #top.add_style("height: 550px")

        top.add_class("spt_reports_top")


        title = DivWdg()
        title.add("Searchable Lists")
        title.add_style("font-size: 18px")
        title.add_style("font-weight: bold")
        title.add_style("text-align: center")
        title.add_style("padding: 10px")
        title.add_style("margin: -10px -10px 0px -10px")

        top.add(title)
        title.add_gradient("background", "background3", 5, -10)
        top.add("<br/>")

        button_div = DivWdg()
        top.add(button_div)
        button = SingleButtonWdg(title="Collapse", icon=IconWdg.ARROW_UP)
        button_div.add(button)
        top.add(button_div)
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_reports_top");
            var element = top.getElement(".spt_reports_list");
            spt.toggle_show_hide(element)

            '''
        } )

        #desc = DivWdg()
        #top.add(desc)
        #desc.add("Dashboard")
        #desc.add_style("width: 600px")

        reports = []

        # read the config file
        """
        from pyasm.widget import WidgetConfig
        tmp_path = __file__
        dir_name = os.path.dirname(tmp_path)
        file_path="%s/../config/reports-conf.xml" % (dir_name)
        config = WidgetConfig.get(file_path=file_path, view="definition")
        element_names = config.get_element_names()

        for element_name in element_names:
            print "element_name: ", element_name
            attrs = config.get_element_attributes(element_name)
            report_data = {}
            kwargs = config.get_display_options(element_name)
            class_name = kwargs.get('class_name')

            report_data['class_name'] = class_name
            report_data['kwargs'] = kwargs
            report_data['title'] = attrs.get("title")
            report_data['description'] = attrs.get("description")

            reports.append(report_data)
        """

        project = Project.get()
        project_code = project.get_code()
        search_type_objs = project.get_search_types()

        filtered = [] 
        for search_type_obj in search_type_objs:
            search_type = search_type_obj.get_value("search_type")

            # FIXME: this code is also present 
            from pyasm.security import get_security_version
            security_version = get_security_version()
            if security_version >= 2 and not search_type.startswith("sthpw/") and not search_type.startswith("config/"):
                security = Environment.get_security()

                table = search_type_obj.get_value("table_name")

                default = "deny"
                key  = { "element": "%s_list" % table }
                key2 = { "element": "%s_list" % table, "project": project_code }
                key3 = { "element": "*" }
                key4 = { "element": "*", "project": project_code }
                keys = [key, key2, key3, key4]
                if not security.check_access("link", keys, "view", default=default):
                    continue

                key = { "code": search_type }
                key2 = { "code": "*" }
                keys = [key, key2]
                if not security.check_access("search_type", keys, "view", default=default):
                    continue
                

                filtered.append(search_type_obj)


        search_type_objs = filtered

        for search_type_sobj in search_type_objs:
            description = search_type_sobj.get_value("description")
            search_type = search_type_sobj.get_value("search_type")



            search = Search(search_type)
            count = search.get_count()

            title_div = DivWdg()
            items_div = DivWdg()
            title_div.add(items_div)
            items_div.add_style("font-size: 9px")
            items_div.add_style("font-weight: italic")
            items_div.add_style("float: right")
            items_div.add("%s item/s" % count)
            title_div.add(search_type_sobj.get_title())

            description_div = DivWdg()
            description_div.add(description)
            description_div.add_style("padding: 5px")
            if not description:
                description_div.add("<br/>(No description)")
                description_div.add_style("font-style: italic")
                description_div.add_style("opacity: 0.3")


            report_data = {
                'title': search_type_sobj.get_title(),
                'title_wdg': title_div,
                'class_name': 'tactic.ui.panel.ViewPanelWdg',
                'kwargs': {
                        'search_type': search_type,
                        'view': 'table',
                        'simple_search_view': 'simple_search'
                    },
                'description': description_div,
                'search_type': search_type_sobj
            }
            reports.append(report_data)


        # create a bunch of panels
        list_div = DivWdg()
        top.add(list_div)
        list_div.add_class("spt_reports_list")


        table = Table()
        list_div.add(table)
        table.add_color("color", "color")
        table.add_style("margin-bottom: 5px")
        table.center()

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


        for i, report in enumerate(reports):

            if i == 0 or i%4 == 0:
                tr = table.add_row()

            td = table.add_cell()
            td.add_style("vertical-align: top")
            td.add_style("padding: 3px")

            class_name = report.get("class_name")
            kwargs = report.get("kwargs")
            title = report.get("title")
            description = report.get("description")

            #image = "<img src='/context/images/getting_started_schema.png'/>"
            image = "<img src='/context/images/getting_started_pipeline.png'/>"


            thumb_div = DivWdg()
            image = thumb_div
            thumb_div.add_border()
            thumb_div.set_box_shadow("1px 1px 1px 1px")

            thumb = ThumbWdg()
            thumb_div.add(thumb)
            thumb.set_sobject(report.get("search_type"))
            thumb.set_icon_size(60)




            behavior = {
            'type': 'click_up',
            'title': title,
            'class_name': class_name,
            'kwargs': kwargs,
            'cbjs_action': '''

            var top = bvr.src_el.getParent(".spt_reports_top");
            //spt.tab.set_main_body_tab();
            spt.tab.set_tab_top(top);
            var kwargs = {};
            spt.tab.add_new(bvr.title, bvr.title, bvr.class_name, bvr.kwargs);
            '''
            }
            title_wdg = report.get("title_wdg")
            schema_wdg = my.get_section_wdg(title_wdg, description, image, behavior)
            td.add(schema_wdg)



        from tactic.ui.container import TabWdg
        tab = TabWdg(show_add=False)
        top.add(tab)



        return top