Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<script setup lang="ts">
import BootstrapModal from "@/components/modals/BootstrapModal.vue";
import FontAwesomeIcon from "@/components/FontAwesomeIcon.vue";
import { computed, onMounted, reactive, ref } from "vue";
import { useRouter } from "vue-router";
import {
GitRepository,
requiredRepositoryFiles,
determineGitIcon,
} from "@/utils/GitRepository";
import { Modal } from "bootstrap";
const props = defineProps<{
modalID: string;
}>();
let createWorkflowModal: Modal | null = null;
const arbitraryWorkflowForm = ref<HTMLFormElement | undefined>(undefined);
const workflowRepositoryElement = ref<HTMLInputElement | undefined>(undefined);
const router = useRouter();
const workflow = reactive<{
repository_url: string;
git_commit_hash: string;
}>({
repository_url: "",
git_commit_hash: "",
});
const formState = reactive<{
loading: boolean;
checkRepoLoading: boolean;
validated: boolean;
allowUpload: boolean;
missingFiles: string[];
unsupportedRepository: boolean;
}>({
validated: false,
allowUpload: false,
loading: false,
checkRepoLoading: false,
missingFiles: [],
unsupportedRepository: false,
});
function modalClosed() {
formState.validated = false;
}
function viewWorkflow() {
console.log("View", workflow);
createWorkflowModal?.hide();
router.push({
name: "arbitrary-workflow",
query: {
repository: encodeURI(workflow.repository_url),
commit_hash: workflow.git_commit_hash,
},
});
}
function checkRepository() {
formState.validated = true;
if (arbitraryWorkflowForm.value?.checkValidity() && !formState.allowUpload) {
formState.unsupportedRepository = false;
formState.missingFiles = [];
workflowRepositoryElement.value?.setCustomValidity("");
try {
const repo = GitRepository.buildRepository(
workflow.repository_url,
workflow.git_commit_hash
);
repo
.checkFilesExist(requiredRepositoryFiles, true)
.then(() => {
formState.allowUpload = true;
})
.catch((e: Error) => {
formState.missingFiles = e.message.split(",");
// Allow execution of the workflow if main.nf and parameter schema are not missing
if (
formState.missingFiles.findIndex(
(file) => file === "main.nf" || file === "nextflow_schema.json"
) < 0
) {
formState.allowUpload = true;
}
});
} catch (e) {
formState.unsupportedRepository = true;
workflowRepositoryElement.value?.setCustomValidity(
"Repository is not supported"
);
}
}
}
const gitIcon = computed<string>(() =>
determineGitIcon(workflow.repository_url)
);
onMounted(() => {
createWorkflowModal = new Modal("#" + props.modalID);
});
</script>
<template>
<bootstrap-modal
:modalID="modalID"
:static-backdrop="false"
modal-label="Create Workflow Modal"
v-on="{ 'hidden.bs.modal': modalClosed }"
>
<template v-slot:header>Start arbitrary Workflow</template>
<template v-slot:body>
<form
id="arbitraryWorkflowForm"
:class="{ 'was-validated': formState.validated }"
ref="arbitraryWorkflowForm"
>
<div class="mb-3">
<label for="workflowRepositoryInput" class="form-label"
>Git Repository URL</label
>
<div class="input-group">
<div class="input-group-text">
<font-awesome-icon :icon="gitIcon" />
</div>
<input
type="url"
class="form-control"
id="workflowRepositoryInput"
placeholder="https://..."
required
ref="workflowRepositoryElement"
v-model="workflow.repository_url"
@change="formState.allowUpload = false"
aria-describedby="gitRepoProviderHelp"
/>
</div>
<div id="gitRepoProviderHelp" class="form-text">
We support Github and GitLab Repositories
</div>
<div class="text-danger">
<div v-if="formState.unsupportedRepository">
Repository is not supported
</div>
</div>
</div>
<div class="mb-3">
<label for="workflowGitCommitInput" class="form-label"
>Git Commit Hash</label
>
<div class="input-group">
<div class="input-group-text">
<font-awesome-icon icon="fa-solid fa-code-commit" />
</div>
<input
type="text"
class="form-control text-lowercase"
id="workflowGitCommitInput"
placeholder="ba8bcd9..."
required
ref="workflowGitCommitHashElement"
maxlength="40"
minlength="40"
pattern="[0-9a-f]{40}"
v-model="workflow.git_commit_hash"
@change="formState.allowUpload = false"
/>
</div>
</div>
<div v-if="formState.missingFiles.length > 0" class="text-danger">
The following files are missing in the repository
<ul>
<li v-for="file in formState.missingFiles" :key="file">
{{ file }}
</li>
</ul>
</div>
</form>
</template>
<template v-slot:footer>
<button
type="button"
class="btn btn-info me-auto"
@click="checkRepository"
:disabled="formState.allowUpload"
>
<span
v-if="formState.checkRepoLoading"
class="spinner-border spinner-border-sm"
role="status"
aria-hidden="true"
></span>
Check Repository
</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
Close
</button>
<button
type="submit"
form="workflowCreateForm"
class="btn btn-primary"
:disabled="formState.loading || !formState.allowUpload"
@click.prevent="viewWorkflow"
>
<span
v-if="formState.loading"
class="spinner-border spinner-border-sm"
role="status"
aria-hidden="true"
></span>
</button>
</template>
</bootstrap-modal>
</template>
<style scoped></style>