Ejemplo n.º 1
0
    def reference_selected(cls, sobject):
        items = cls.get_selected()

        # get all of the items already connected to this sobject
        from pyasm.biz import SObjectConnection
        # create a connection for each item
        for item in items:
            SObjectConnection.create(sobject, item)
Ejemplo n.º 2
0
    def reference_selected(cls, sobject):
        items = cls.get_selected()

        # get all of the items already connected to this sobject
        from pyasm.biz import SObjectConnection
        # create a connection for each item
        for item in items:
            SObjectConnection.create(sobject, item)
Ejemplo n.º 3
0
    def execute(self):

        name = self.get_input_name()
        web = WebContainer.get_web()
        if not web.get_form_value(self.get_input_name()):
            return

        clipboard_items = Clipboard.get_all(category='select')
        sobject = self.sobject

        context = self.get_option("context")
        if not context:
            context = 'reference'

        for item in clipboard_items:
            parent = item.get_parent()
            SObjectConnection.create(parent, sobject, context)
Ejemplo n.º 4
0
    def execute(self):

        name = self.get_input_name()
        web = WebContainer.get_web()
        if not web.get_form_value( self.get_input_name() ):
            return

        clipboard_items = Clipboard.get_all(category='select')
        sobject = self.sobject

        context = self.get_option("context")
        if not context:
            context = 'reference'

        for item in clipboard_items:
            parent = item.get_parent()
            SObjectConnection.create(parent, sobject, context)
Ejemplo n.º 5
0
    def execute(self):
        web = WebContainer.get_web()
        connection_id = web.get_form_value("connection_id")

        connection = SObjectConnection.get_by_id(connection_id)
        if connection:
            connection.delete()

        self.description = "Deleted connection"
Ejemplo n.º 6
0
    def execute(self):
        web = WebContainer.get_web()
        connection_id = web.get_form_value("connection_id")

        connection = SObjectConnection.get_by_id(connection_id)
        if connection:
            connection.delete()

        self.description = "Deleted connection"
Ejemplo n.º 7
0
    def preprocess(self):
        direction = self.get_option("direction")
        self.info = {}
        if not direction:
            direction = "dst"
        for sobject in self.sobjects:
            src_sobject = sobject
            dst_sobjects = []
            if isinstance(src_sobject, SObjectConnection):
                connection = src_sobject

                dst_sobject = connection.get_sobject(direction)
                src_sobject = connection.get_sobject(direction="src")

                connections = [connection]
                dst_sobjects = [dst_sobject]
            else:
                connections, dst_sobjects = SObjectConnection.get_connected_sobjects(
                    src_sobject, direction)

            self.info[sobject.get_search_key()] = (connections, dst_sobjects,
                                                   sobject)

        # reorder sobjects
        sobj_dict = {}
        idx = 0
        for connections, dst_sobjects, sobject in self.info.values():
            obj = dst_sobjects[0]
            # obj has been deleted
            if obj:
                key = '%s_%s' % (obj.get_value('timestamp'), obj.get_id())
            else:
                key = '000_deleted_%s' % idx
            sobj_dict[key] = sobject
            idx += 1

        sobj_list = Common.sort_dict(sobj_dict, reverse=True)

        self.sobjects = sobj_list
Ejemplo n.º 8
0
    def preprocess(self):
        direction = self.get_option("direction")
        self.info = {}
        if not direction:
            direction = "dst"
        for sobject in self.sobjects:
            src_sobject = sobject
            dst_sobjects = []
            if isinstance(src_sobject, SObjectConnection):
                connection = src_sobject

                dst_sobject = connection.get_sobject(direction)
                src_sobject = connection.get_sobject(direction="src")

                connections = [connection]
                dst_sobjects = [dst_sobject]
            else:
                connections, dst_sobjects = SObjectConnection.get_connected_sobjects(src_sobject, direction)

            self.info[sobject.get_search_key()] = (connections, dst_sobjects, sobject)

        # reorder sobjects
        sobj_dict = {}
        idx = 0
        for connections, dst_sobjects, sobject in self.info.values():
            obj = dst_sobjects[0]
            # obj has been deleted
            if obj:
                key = '%s_%s' %(obj.get_value('timestamp'), obj.get_id())
            else:
                key = '000_deleted_%s' %idx
            sobj_dict[key] = sobject
            idx += 1

        sobj_list = Common.sort_dict(sobj_dict, reverse=True)

        self.sobjects = sobj_list
Ejemplo n.º 9
0
    def get_display(self):

        # get all of the options
        direction = self.get_option("direction")
        if not direction:
            direction = "dst"

        icon_size = self.get_option("icon_size")
        if not icon_size:
            icon_size = 60

        src_sobject = self.get_current_sobject()
        dst_sobjects = []

        if isinstance(src_sobject, SObjectConnection):
            connection = src_sobject

            dst_sobject = connection.get_sobject(direction)
            src_sobject = connection.get_sobject(direction="src")

            connections = [connection]
            dst_sobjects = [dst_sobject]
        else:
            connections, dst_sobjects = SObjectConnection.get_connected_sobjects(
                src_sobject, direction)

        div = DivWdg()
        div.set_id("connection_%s" % src_sobject.get_id())

        # set the ajax options
        self.set_ajax_top(div)
        self.set_ajax_option("search_key", src_sobject.get_search_key())
        self.register_cmd("pyasm.widget.SObjectConnectionRemoveCbk")

        table = Table()
        table.set_max_width()
        table.set_class("minimal")
        count = 0
        for dst_sobject in dst_sobjects:
            tr = table.add_row()
            if not dst_sobject:
                table.add_cell("referenced to retired or deleted asset....")
                continue
            if dst_sobject.is_retired():
                tr.add_class("retired_row")

            thumb = ThumbWdg()
            thumb.set_show_filename(True)

            thumb.set_icon_size(icon_size)
            thumb.set_sobject(dst_sobject)
            td = table.add_cell(thumb)
            td.add_style("padding: 1px")
            td.add_style("width: 20%")

            id = dst_sobject.get_id()
            name = dst_sobject.get_name()
            code = dst_sobject.get_code()
            if code == str(id):
                pass
            elif name == code:
                td = table.add_cell(name)
                td.add_style("width: 20%")
            else:
                td = table.add_cell("%s<br/>%s" % (name, code))
                td.add_style("width: 20%")
            if dst_sobject.has_value("title"):
                td = table.add_cell(dst_sobject.get_value("title"))
            elif dst_sobject.has_value("description"):
                td = table.add_cell(dst_sobject.get_value("description"))
                if dst_sobject.has_value("keywords"):
                    table.add_cell(dst_sobject.get_value("keywords"))

            # remove connection
            connection = connections[count]
            connection_id = connection.get_id()
            self.set_ajax_option("connection_id", connection_id)
            refresh_script = self.get_refresh_script(False)

            remove = IconButtonWdg("Remove Connection", IconWdg.DELETE)
            remove.add_event("onclick", refresh_script)

            table.add_cell(remove)

            count += 1

        div.add(table)
        return div
Ejemplo n.º 10
0
    def get_display(self):

        self.search_key = self.kwargs.get("search_key") 
        self.context = self.kwargs.get("context") 

        assert self.search_key
        assert self.context

        top = DivWdg()
        self.set_as_panel(top)
        top.add_class("spt_review_top")

        table = Table()
        top.add(table)
        table.add_row()
        left = table.add_cell()
        left.add_style("vertical-align: top")



        button = IconButtonWdg("Visual Notes", IconWdg.EDIT)
        button.add_behavior( {
        'type': 'click_up',
        'kwargs': {
            'search_key': self.search_key,
            'context': self.context,
        },
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_review_top");
        var content = top.getElement(".spt_review_content");
        spt.panel.load(content, "tactic.ui.widget.visual_notes_wdg.VisualNotesWdg", bvr.kwargs);
        '''
        } )
        left.add(button)


        # add a refresh button and a gear menu
        button = IconButtonWdg("Refresh", IconWdg.REFRESH)
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var panel = bvr.src_el.getParent(".spt_review_top");
        spt.panel.refresh(panel);
        '''
        } )
        left.add(button)






        right = table.add_cell()
        right.add_style("vertical-align: top")
        right.add("Image Area")


        content_div = DivWdg()
        content_div.add_class("spt_review_content")
        content_div.add_style("padding: 5px")
        content_div.add_style("margin: 5px")
        content_div.add_style("border: solid 1px #999")
        content_div.add_style("min-width: 500px")
        content_div.add_style("min-height: 400px")
        content_div.add_style("height: 100%")

        right.add(content_div)



        sobject = Search.get_by_search_key(self.search_key)

        note_context = "%s|note" % self.context
        snapshots = Search.eval("@SOBJECT(sthpw/snapshot['context','=','%s'])" % note_context, [sobject])

        vnotes_div = DivWdg()
        vnotes_div.add_style("overflow: auto")
        vnotes_div.add_style("width: 200px")
        vnotes_div.add_style("min-height: 400px")
        vnotes_div.add_style("max-height: 600px")
        vnotes_div.add_style("border: solid 1px #999")
        vnotes_div.add_style("padding: 5px")
        vnotes_div.add_style("margin: 5px")

        left.add(vnotes_div)

        if not snapshots:
            vnotes_div.add("<b>No review notes available</b>")

            notes_wdg = VisualNotesWdg(search_key=self.search_key,context=self.context)
            content_div.add(notes_wdg)



        for snapshot in snapshots:
            vnote_div = DivWdg()
            vnotes_div.add(vnote_div)

            file_obj = snapshot.get_file_by_type('main')
            if not file_obj:
                vnote_div.add("None found")
                continue

            rel_path = file_obj.get_value("relative_dir")
            file_name = file_obj.get_value("file_name")
            image_url = "/assets/%s/%s" % (rel_path, file_name)


            login = snapshot.get_value("login")
            date = snapshot.get_value("timestamp")
            import dateutil
            date_str = dateutil.parser.parse(date).strftime("%b %m %Y - %H:%M")


            login_div = DivWdg()
            login_div.add_style("padding: 2px")
            login_div.add("User: "******"<b>%s</b><br/>" % login )
            login_div.add("Date: ")
            login_div.add( "<b>%s</b><br/>" % date_str )
            vnote_div.add(login_div)



            from pyasm.widget import ThumbWdg
            thumb_div = DivWdg()
            thumb_div.add_style("margin-left: 10px")
            thumb = ThumbWdg()
            thumb_div.add(thumb)
            thumb.set_has_img_link(False)
            thumb.set_option("detail", "false")
            thumb.set_option("icon_size", "80")
            thumb.set_sobject(snapshot)
            vnote_div.add(thumb_div)
            #file_obj = snapshot.get_file_by_type('icon')
            #rel_path = file_obj.get_value("relative_dir")
            #file_name = file_obj.get_value("file_name")
            #icon_url = "/assets/%s/%s" % (rel_path, file_name)
            #vnote_div.add("<img src='%s'/>" % icon_url )

            #vnote_div.add(snapshot.get_code() )
            vnote_div.add_attr("spt_image_url", image_url )
            vnote_div.add_class('hand')

            vnote_div.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var value = bvr.src_el.innerHTML;
            var image_url = bvr.src_el.getAttribute("spt_image_url");

            var top = bvr.src_el.getParent(".spt_review_top");
            var content = top.getElement(".spt_review_content");
            content.innerHTML = "<img src='"+image_url+"'/>";
            '''
            } )




            # get the related note to this vnote
            #notes = vnotes_div.get_related_notes()
            search = Search("sthpw/note")
            search.add_parent_filter(sobject)
            notes = search.get_sobjects()

            #for note in notes:
            #    vnote_div.add(note.get_value("note"))

            from pyasm.biz import SObjectConnection 
            connections, related_notes = SObjectConnection.get_connected_sobjects(snapshot, direction='src')
            for related_note in related_notes:
                vnote_div.add(related_note.get_value("note") )
                
            print "related_notes: ", related_notes


            vnote_div.add("<hr/>")




        return top
Ejemplo n.º 11
0
    def get_display(self):

        # get all of the options
        direction = self.get_option("direction")
        if not direction:
            direction = "dst"

        icon_size = self.get_option("icon_size")
        if not icon_size:
            icon_size = 60

        src_sobject = self.get_current_sobject()
        dst_sobjects = []

        if isinstance(src_sobject, SObjectConnection):
            connection = src_sobject

            dst_sobject = connection.get_sobject(direction)
            src_sobject = connection.get_sobject(direction="src")

            connections = [connection]
            dst_sobjects = [dst_sobject]
        else:
            connections, dst_sobjects = SObjectConnection.get_connected_sobjects(src_sobject, direction)


        div = DivWdg()
        div.set_id("connection_%s" % src_sobject.get_id() )

        # set the ajax options
        self.set_ajax_top(div)
        self.set_ajax_option("search_key", src_sobject.get_search_key() )
        self.register_cmd("pyasm.widget.SObjectConnectionRemoveCbk")

        table = Table()
        table.set_max_width()
        table.set_class("minimal")
        count = 0
        for dst_sobject in dst_sobjects:
            tr = table.add_row()
            if not dst_sobject:
                table.add_cell("referenced to retired or deleted asset....")
                continue
            if dst_sobject.is_retired():
                tr.add_class("retired_row")

            thumb = ThumbWdg()
            thumb.set_show_filename(True)

            thumb.set_icon_size(icon_size)
            thumb.set_sobject(dst_sobject)
            td = table.add_cell(thumb)
            td.add_style("padding: 1px")
            td.add_style("width: 20%")

            id = dst_sobject.get_id()
            name = dst_sobject.get_name()
            code = dst_sobject.get_code()
            if code == str(id):
                pass 
            elif name == code:
                td = table.add_cell(name)
                td.add_style("width: 20%")
            else:
                td = table.add_cell("%s<br/>%s" % (name,code) )
                td.add_style("width: 20%")
            if dst_sobject.has_value("title"):
                td = table.add_cell(dst_sobject.get_value("title") )
            elif dst_sobject.has_value("description"):
                td = table.add_cell(dst_sobject.get_value("description") )
                if dst_sobject.has_value("keywords"):
                     table.add_cell(dst_sobject.get_value("keywords") )
            
            # remove connection
            connection = connections[count]
            connection_id = connection.get_id()
            self.set_ajax_option("connection_id", connection_id )
            refresh_script = self.get_refresh_script(False)

            remove = IconButtonWdg("Remove Connection", IconWdg.DELETE)
            remove.add_event("onclick", refresh_script)

            table.add_cell(remove)

            count += 1

        div.add(table)
        return div
Ejemplo n.º 12
0
    def get_display(my):

        my.search_key = my.kwargs.get("search_key")
        my.context = my.kwargs.get("context")

        assert my.search_key
        assert my.context

        top = DivWdg()
        my.set_as_panel(top)
        top.add_class("spt_review_top")

        table = Table()
        top.add(table)
        table.add_row()
        left = table.add_cell()
        left.add_style("vertical-align: top")

        button = IconButtonWdg("Visual Notes", IconWdg.EDIT)
        button.add_behavior(
            {
                "type": "click_up",
                "kwargs": {"search_key": my.search_key, "context": my.context},
                "cbjs_action": """
        var top = bvr.src_el.getParent(".spt_review_top");
        var content = top.getElement(".spt_review_content");
        spt.panel.load(content, "tactic.ui.widget.visual_notes_wdg.VisualNotesWdg", bvr.kwargs);
        """,
            }
        )
        left.add(button)

        # add a refresh button and a gear menu
        button = IconButtonWdg("Refresh", IconWdg.REFRESH)
        button.add_behavior(
            {
                "type": "click_up",
                "cbjs_action": """
        var panel = bvr.src_el.getParent(".spt_review_top");
        spt.panel.refresh(panel);
        """,
            }
        )
        left.add(button)

        right = table.add_cell()
        right.add_style("vertical-align: top")
        right.add("Image Area")

        content_div = DivWdg()
        content_div.add_class("spt_review_content")
        content_div.add_style("padding: 5px")
        content_div.add_style("margin: 5px")
        content_div.add_style("border: solid 1px #999")
        content_div.add_style("min-width: 500px")
        content_div.add_style("min-height: 400px")
        content_div.add_style("height: 100%")

        right.add(content_div)

        sobject = Search.get_by_search_key(my.search_key)

        note_context = "%s|note" % my.context
        snapshots = Search.eval("@SOBJECT(sthpw/snapshot['context','=','%s'])" % note_context, [sobject])

        vnotes_div = DivWdg()
        vnotes_div.add_style("overflow: auto")
        vnotes_div.add_style("width: 200px")
        vnotes_div.add_style("min-height: 400px")
        vnotes_div.add_style("max-height: 600px")
        vnotes_div.add_style("border: solid 1px #999")
        vnotes_div.add_style("padding: 5px")
        vnotes_div.add_style("margin: 5px")

        left.add(vnotes_div)

        if not snapshots:
            vnotes_div.add("<b>No review notes available</b>")

            notes_wdg = VisualNotesWdg(search_key=my.search_key, context=my.context)
            content_div.add(notes_wdg)

        for snapshot in snapshots:
            vnote_div = DivWdg()
            vnotes_div.add(vnote_div)

            file_obj = snapshot.get_file_by_type("main")
            if not file_obj:
                vnote_div.add("None found")
                continue

            rel_path = file_obj.get_value("relative_dir")
            file_name = file_obj.get_value("file_name")
            image_url = "/assets/%s/%s" % (rel_path, file_name)

            login = snapshot.get_value("login")
            date = snapshot.get_value("timestamp")
            import dateutil

            date_str = dateutil.parser.parse(date).strftime("%b %m %Y - %H:%M")

            login_div = DivWdg()
            login_div.add_style("padding: 2px")
            login_div.add("User: "******"<b>%s</b><br/>" % login)
            login_div.add("Date: ")
            login_div.add("<b>%s</b><br/>" % date_str)
            vnote_div.add(login_div)

            from pyasm.widget import ThumbWdg

            thumb_div = DivWdg()
            thumb_div.add_style("margin-left: 10px")
            thumb = ThumbWdg()
            thumb_div.add(thumb)
            thumb.set_has_img_link(False)
            thumb.set_option("detail", "false")
            thumb.set_option("icon_size", "80")
            thumb.set_sobject(snapshot)
            vnote_div.add(thumb_div)
            # file_obj = snapshot.get_file_by_type('icon')
            # rel_path = file_obj.get_value("relative_dir")
            # file_name = file_obj.get_value("file_name")
            # icon_url = "/assets/%s/%s" % (rel_path, file_name)
            # vnote_div.add("<img src='%s'/>" % icon_url )

            # vnote_div.add(snapshot.get_code() )
            vnote_div.add_attr("spt_image_url", image_url)
            vnote_div.add_class("hand")

            vnote_div.add_behavior(
                {
                    "type": "click_up",
                    "cbjs_action": """
            var value = bvr.src_el.innerHTML;
            var image_url = bvr.src_el.getAttribute("spt_image_url");

            var top = bvr.src_el.getParent(".spt_review_top");
            var content = top.getElement(".spt_review_content");
            content.innerHTML = "<img src='"+image_url+"'/>";
            """,
                }
            )

            # get the related note to this vnote
            # notes = vnotes_div.get_related_notes()
            search = Search("sthpw/note")
            search.add_parent_filter(sobject)
            notes = search.get_sobjects()

            # for note in notes:
            #    vnote_div.add(note.get_value("note"))

            from pyasm.biz import SObjectConnection

            connections, related_notes = SObjectConnection.get_connected_sobjects(snapshot, direction="src")
            for related_note in related_notes:
                vnote_div.add(related_note.get_value("note"))

            print "related_notes: ", related_notes

            vnote_div.add("<hr/>")

        return top