Ejemplo n.º 1
0
 def editor(self, trans, id=None, version=None):
     """
     Render the main workflow editor interface. The canvas is embedded as
     an iframe (necessary for scrolling to work properly), which is
     rendered by `editor_canvas`.
     """
     if not id:
         error("Invalid workflow id")
     stored = self.get_stored_workflow(trans, id)
     # The following query loads all user-owned workflows,
     # So that they can be copied or inserted in the workflow editor.
     workflows = trans.sa_session.query(model.StoredWorkflow) \
         .filter_by(user=trans.user, deleted=False) \
         .order_by(desc(model.StoredWorkflow.table.c.update_time)) \
         .options(joinedload('latest_workflow').joinedload('steps')) \
         .all()
     if version is None:
         version = len(stored.workflows) - 1
     else:
         version = int(version)
     return trans.fill_template("workflow/editor.mako",
                                workflows=workflows,
                                stored=stored,
                                version=version,
                                annotation=self.get_item_annotation_str(
                                    trans.sa_session, trans.user, stored))
Ejemplo n.º 2
0
 def editor(self, trans, id=None, version=None):
     """
     Render the main workflow editor interface. The canvas is embedded as
     an iframe (necessary for scrolling to work properly), which is
     rendered by `editor_canvas`.
     """
     if not id:
         error("Invalid workflow id")
     stored = self.get_stored_workflow(trans, id)
     # The following query loads all user-owned workflows,
     # So that they can be copied or inserted in the workflow editor.
     workflows = trans.sa_session.query(model.StoredWorkflow) \
         .filter_by(user=trans.user, deleted=False) \
         .order_by(desc(model.StoredWorkflow.table.c.update_time)) \
         .options(joinedload('latest_workflow').joinedload('steps')) \
         .all()
     if version is None:
         version = len(stored.workflows) - 1
     else:
         version = int(version)
     return trans.fill_template("workflow/editor.mako",
                                workflows=workflows,
                                stored=stored,
                                version=version,
                                annotation=self.get_item_annotation_str(trans.sa_session, trans.user, stored))
Ejemplo n.º 3
0
 def list_for_run(self, trans):
     """
     Render workflow list for analysis view (just allows running workflow
     or switching to management view)
     """
     user = trans.get_user()
     workflows = trans.sa_session.query( model.StoredWorkflow ) \
         .filter_by( user=user, deleted=False ) \
         .order_by( desc( model.StoredWorkflow.table.c.update_time ) ) \
         .all()
     shared_by_others = trans.sa_session \
         .query( model.StoredWorkflowUserShareAssociation ) \
         .filter_by( user=user ) \
         .filter( model.StoredWorkflow.deleted == False ) \
         .order_by( desc( model.StoredWorkflow.table.c.update_time ) ) \
         .all()
     return trans.fill_template("workflow/list_for_run.mako",
                                workflows=workflows,
                                shared_by_others=shared_by_others)
Ejemplo n.º 4
0
 def list(self, trans):
     """
     Render workflow main page (management of existing workflows)
     """
     user = trans.get_user()
     workflows = trans.sa_session.query( model.StoredWorkflow ) \
         .filter_by( user=user, deleted=False ) \
         .order_by( desc( model.StoredWorkflow.table.c.update_time ) ) \
         .all()
     shared_by_others = trans.sa_session \
         .query( model.StoredWorkflowUserShareAssociation ) \
         .filter_by( user=user ) \
         .join( 'stored_workflow' ) \
         .filter( model.StoredWorkflow.deleted == False ) \
         .order_by( desc( model.StoredWorkflow.update_time ) ) \
         .all()
     return trans.fill_template("workflow/list.mako",
                                workflows=workflows,
                                shared_by_others=shared_by_others)
Ejemplo n.º 5
0
 def list_for_run( self, trans ):
     """
     Render workflow list for analysis view (just allows running workflow
     or switching to management view)
     """
     user = trans.get_user()
     workflows = trans.sa_session.query( model.StoredWorkflow ) \
         .filter_by( user=user, deleted=False ) \
         .order_by( desc( model.StoredWorkflow.table.c.update_time ) ) \
         .all()
     shared_by_others = trans.sa_session \
         .query( model.StoredWorkflowUserShareAssociation ) \
         .filter_by( user=user ) \
         .filter( model.StoredWorkflow.deleted == False ) \
         .order_by( desc( model.StoredWorkflow.table.c.update_time ) ) \
         .all()
     return trans.fill_template( "workflow/list_for_run.mako",
                                 workflows = workflows,
                                 shared_by_others = shared_by_others )
Ejemplo n.º 6
0
 def list( self, trans ):
     """
     Render workflow main page (management of existing workflows)
     """
     user = trans.get_user()
     workflows = trans.sa_session.query( model.StoredWorkflow ) \
         .filter_by( user=user, deleted=False ) \
         .order_by( desc( model.StoredWorkflow.table.c.update_time ) ) \
         .all()
     shared_by_others = trans.sa_session \
         .query( model.StoredWorkflowUserShareAssociation ) \
         .filter_by( user=user ) \
         .join( 'stored_workflow' ) \
         .filter( model.StoredWorkflow.deleted == False ) \
         .order_by( desc( model.StoredWorkflow.update_time ) ) \
         .all()
     return trans.fill_template( "workflow/list.mako",
                                 workflows = workflows,
                                 shared_by_others = shared_by_others )
Ejemplo n.º 7
0
 def configure_menu(self, trans, workflow_ids=None):
     user = trans.get_user()
     if trans.request.method == "POST":
         if workflow_ids is None:
             workflow_ids = []
         elif type(workflow_ids) != list:
             workflow_ids = [workflow_ids]
         sess = trans.sa_session
         # This explicit remove seems like a hack, need to figure out
         # how to make the association do it automatically.
         for m in user.stored_workflow_menu_entries:
             sess.delete(m)
         user.stored_workflow_menu_entries = []
         q = sess.query(model.StoredWorkflow)
         # To ensure id list is unique
         seen_workflow_ids = set()
         for id in workflow_ids:
             if id in seen_workflow_ids:
                 continue
             else:
                 seen_workflow_ids.add(id)
             m = model.StoredWorkflowMenuEntry()
             m.stored_workflow = q.get(id)
             user.stored_workflow_menu_entries.append(m)
         sess.flush()
         return trans.show_message("Menu updated", refresh_frames=['tools'])
     else:
         user = trans.get_user()
         ids_in_menu = set([
             x.stored_workflow_id for x in user.stored_workflow_menu_entries
         ])
         workflows = trans.sa_session.query( model.StoredWorkflow ) \
             .filter_by( user=user, deleted=False ) \
             .order_by( desc( model.StoredWorkflow.table.c.update_time ) ) \
             .all()
         shared_by_others = trans.sa_session \
             .query( model.StoredWorkflowUserShareAssociation ) \
             .filter_by( user=user ) \
             .filter( model.StoredWorkflow.deleted == False ) \
             .all()
         return trans.fill_template("workflow/configure_menu.mako",
                                    workflows=workflows,
                                    shared_by_others=shared_by_others,
                                    ids_in_menu=ids_in_menu)
Ejemplo n.º 8
0
 def configure_menu( self, trans, workflow_ids=None ):
     user = trans.get_user()
     if trans.request.method == "POST":
         if workflow_ids is None:
             workflow_ids = []
         elif type( workflow_ids ) != list:
             workflow_ids = [ workflow_ids ]
         sess = trans.sa_session
         # This explicit remove seems like a hack, need to figure out
         # how to make the association do it automatically.
         for m in user.stored_workflow_menu_entries:
             sess.delete( m )
         user.stored_workflow_menu_entries = []
         q = sess.query( model.StoredWorkflow )
         # To ensure id list is unique
         seen_workflow_ids = set()
         for id in workflow_ids:
             if id in seen_workflow_ids:
                 continue
             else:
                 seen_workflow_ids.add( id )
             m = model.StoredWorkflowMenuEntry()
             m.stored_workflow = q.get( id )
             user.stored_workflow_menu_entries.append( m )
         sess.flush()
         return trans.show_message( "Menu updated", refresh_frames=['tools'] )
     else:                
         user = trans.get_user()
         ids_in_menu = set( [ x.stored_workflow_id for x in user.stored_workflow_menu_entries ] )
         workflows = trans.sa_session.query( model.StoredWorkflow ) \
             .filter_by( user=user, deleted=False ) \
             .order_by( desc( model.StoredWorkflow.table.c.update_time ) ) \
             .all()
         shared_by_others = trans.sa_session \
             .query( model.StoredWorkflowUserShareAssociation ) \
             .filter_by( user=user ) \
             .filter( model.StoredWorkflow.deleted == False ) \
             .all()
         return trans.fill_template( "workflow/configure_menu.mako",
                                     workflows=workflows,
                                     shared_by_others=shared_by_others,
                                     ids_in_menu=ids_in_menu )
Ejemplo n.º 9
0
    def editor(self, trans, id=None, workflow_id=None, version=None):
        """
        Render the main workflow editor interface. The canvas is embedded as
        an iframe (necessary for scrolling to work properly), which is
        rendered by `editor_canvas`.
        """
        if not id:
            if workflow_id:
                workflow = trans.sa_session.query(model.Workflow).get(trans.security.decode_id(workflow_id))
                stored_workflow = workflow.stored_workflow
                self.security_check(trans, stored_workflow, True, False)
                stored_workflow_id = trans.security.encode_id(stored_workflow.id)
                return trans.response.send_redirect(f'{url_for("/")}workflow/editor?id={stored_workflow_id}')

            error("Invalid workflow id")
        stored = self.get_stored_workflow(trans, id)
        # The following query loads all user-owned workflows,
        # So that they can be copied or inserted in the workflow editor.
        workflows = trans.sa_session.query(model.StoredWorkflow) \
            .filter_by(user=trans.user, deleted=False, hidden=False) \
            .order_by(desc(model.StoredWorkflow.table.c.update_time)) \
            .options(joinedload('latest_workflow').joinedload('steps')) \
            .all()
        if version is None:
            version = len(stored.workflows) - 1
        else:
            version = int(version)

        # create workflow module models
        module_sections = []
        for module_section in load_module_sections(trans).values():
            module_sections.append({
                "title": module_section.get("title"),
                "name": module_section.get("name"),
                "elems": [{
                    "name": elem.get("name"),
                    "title": elem.get("title"),
                    "description": elem.get("description")
                } for elem in module_section.get("modules")]
            })

        # create data manager tool models
        data_managers = []
        if trans.user_is_admin and trans.app.data_managers.data_managers:
            for data_manager_val in trans.app.data_managers.data_managers.values():
                tool = data_manager_val.tool
                if not tool.hidden:
                    data_managers.append({
                        "id": tool.id,
                        "name": tool.name,
                        "hidden": tool.hidden,
                        "description": tool.description,
                        "is_workflow_compatible": tool.is_workflow_compatible
                    })

        # create workflow models
        workflows = [{
            'id': trans.security.encode_id(workflow.id),
            'latest_id': trans.security.encode_id(workflow.latest_workflow.id),
            'step_count': len(workflow.latest_workflow.steps),
            'name': workflow.name
        } for workflow in workflows if workflow.id != stored.id]

        # identify item tags
        item_tags = [tag for tag in stored.tags if tag.user == trans.user]
        item_tag_names = []
        for ta in item_tags:
            item_tag_names.append(escape(ta.tag.name))

        # build workflow editor model
        editor_config = {
            'id': trans.security.encode_id(stored.id),
            'name': stored.name,
            'tags': item_tag_names,
            'initialVersion': version,
            'annotation': self.get_item_annotation_str(trans.sa_session, trans.user, stored),
            'toolbox': trans.app.toolbox.to_dict(trans),
            'moduleSections': module_sections,
            'dataManagers': data_managers,
            'workflows': workflows
        }

        # parse to mako
        return trans.fill_template("workflow/editor.mako", editor_config=editor_config)