Skip to content

Commit

Permalink
use create endpoint for name, ann & tags, else use save as endpoint
Browse files Browse the repository at this point in the history
Also, use `scopePointerStore` for actual Save As operation as well
  • Loading branch information
ahmedhamidawan committed Nov 7, 2023
1 parent 857af57 commit bbd004d
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 24 deletions.
2 changes: 1 addition & 1 deletion client/src/components/Workflow/Editor/Attributes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
:state="!nameCurrent ? false : null"
@keyup="$emit('update:nameCurrent', nameCurrent)" />
</div>
<div v-if="versionCurrent !== null" id="workflow-version-area" class="mt-2">
<div v-if="versionOptions.length > 0" id="workflow-version-area" class="mt-2">
<b>Version</b>
<b-form-select v-model="versionCurrent" @change="onVersion">
<b-form-select-option v-for="v in versionOptions" :key="v.version" :value="v.version">
Expand Down
86 changes: 64 additions & 22 deletions client/src/components/Workflow/Editor/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
title="Save As a New Workflow"
ok-title="Save"
cancel-title="Cancel"
@ok="doSaveAs">
@ok="doSaveAs(false)">
<b-form-group label="Name">
<b-form-input v-model="saveAsName" />
</b-form-group>
Expand Down Expand Up @@ -257,14 +257,19 @@ export default {
});
const hasChanges = ref(false);
const initialLoading = ref(true);
const hasInvalidConnections = computed(() => Object.keys(connectionStore.invalidConnections).length > 0);
stepStore.$subscribe((_mutation, _state) => {
hasChanges.value = true;
if (!initialLoading.value) {
hasChanges.value = true;
}
});
commentStore.$subscribe((_mutation, _state) => {
hasChanges.value = true;
if (!initialLoading.value) {
hasChanges.value = true;
}
});
function resetStores() {
Expand All @@ -279,8 +284,6 @@ export default {
emit("update:confirmation", false);
});
const initialLoading = ref(true);
return {
id,
connectionStore,
Expand Down Expand Up @@ -358,18 +361,23 @@ export default {
}
},
annotation(newAnnotation, oldAnnotation) {
if (newAnnotation != oldAnnotation) {
if (newAnnotation != oldAnnotation && !this.isNewTempWorkflow) {
this.hasChanges = true;
}
},
name(newName, oldName) {
if (newName != oldName) {
if (newName != oldName && !this.isNewTempWorkflow) {
this.hasChanges = true;
}
},
hasChanges() {
this.$emit("update:confirmation", this.hasChanges);
},
initialVersion(newVal, oldVal) {
if (newVal != oldVal && oldVal === undefined) {
this.version = this.initialVersion;
}
},
},
async created() {
this.lastQueue = new LastQueue();
Expand Down Expand Up @@ -524,8 +532,8 @@ export default {
window.location = `${getAppRoot()}api/workflows/${this.id}/download?format=json-download`;
},
async doSaveAs(create = false) {
const rename_name = this.saveAsName ?? create ? this.name : `SavedAs_${this.name}`;
const rename_annotation = this.saveAsAnnotation ?? create ? this.annotation : "";
const rename_name = create ? this.name : this.saveAsName ?? `SavedAs_${this.name}`;
const rename_annotation = create ? this.annotation || "" : this.saveAsAnnotation ?? "";
// This is an old web controller endpoint that wants form data posted...
const formData = new FormData();
Expand All @@ -538,16 +546,7 @@ export default {
const response = await axios.post(`${getAppRoot()}workflow/save_workflow_as`, formData);
const newId = response.data;
if (create) {
const { addScopePointer } = useScopePointerStore();
// map scoped stores to existing stores, before updating the id
addScopePointer(newId, this.id);
this.id = newId;
}
await this.onSave();
this.hasChanges = false;
this.$router.replace({ query: { id: newId } });
await this.routeToWorkflow(newId);
} catch (e) {
this.onWorkflowError("Saving workflow failed, please contact an administrator.");
}
Expand Down Expand Up @@ -575,7 +574,26 @@ export default {
const step = { ...this.steps[nodeId], annotation: newAnnotation };
this.onUpdateStep(step);
},
onCreate() {
async routeToWorkflow(id) {
const { addScopePointer, scope } = useScopePointerStore();
let pointedTo;
// the current workflow id might be pointing to existing stores
const originalPointed = scope(this.id);
if (originalPointed !== this.id) {
pointedTo = originalPointed;
} else {
pointedTo = this.id;
}
// map scoped stores to existing stores, before updating the id
addScopePointer(id, pointedTo);
this.id = id;
await this.onSave();
this.hasChanges = false;
this.$router.replace({ query: { id } });
},
async onCreate() {
if (!this.name) {
const response = "Please provide a name for your workflow.";
this.onWorkflowError("Creating workflow failed", response, {
Expand All @@ -586,8 +604,32 @@ export default {
this.onAttributes();
return;
}
this.hasChanges = false;
this.doSaveAs(true);
try {
// if nothing other than payload vars changed, just use `create` endpoint
if (!this.hasChanges) {
const payload = {
workflow_name: this.name,
workflow_annotation: this.annotation || "",
workflow_tags: this.tags,
};
const { data } = await axios.put(`${getAppRoot()}workflow/create`, payload);
const { id } = data;
await this.routeToWorkflow(id);
} else {
// otherwise, use `save_as` endpoint to include steps, etc.
this.hasChanges = false;
await this.doSaveAs(true);
}
} catch (e) {
this.onWorkflowError("Creating workflow failed"),
e || "Please contact an administrator.",
{
Ok: () => {
this.hideModal();
},
};
}
},
onSetData(stepId, newData) {
this.lastQueue
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Workflow/Editor/Options.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async function onSave() {
variant="link"
aria-label="Save Workflow"
class="editor-button-save"
:disabled="!hasChanges"
:disabled="!isNewTempWorkflow && !hasChanges"
@click="onSave">
<span class="fa fa-floppy-o" />
</BButton>
Expand Down
7 changes: 7 additions & 0 deletions lib/galaxy/webapps/galaxy/controllers/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ def create(self, trans, payload=None, **kwd):
user = trans.get_user()
workflow_name = payload.get("workflow_name")
workflow_annotation = payload.get("workflow_annotation")
workflow_tags = payload.get("workflow_tags", [])
if not workflow_name:
return self.message_exception(trans, "Please provide a workflow name.")
# Create the new stored workflow
Expand All @@ -379,6 +380,12 @@ def create(self, trans, payload=None, **kwd):
# Add annotation.
workflow_annotation = sanitize_html(workflow_annotation)
self.add_item_annotation(trans.sa_session, trans.get_user(), stored_workflow, workflow_annotation)
# Add tags
trans.tag_handler.set_tags_from_list(
trans.user,
stored_workflow,
workflow_tags,
)
# Persist
session = trans.sa_session
session.add(stored_workflow)
Expand Down

0 comments on commit bbd004d

Please sign in to comment.