Great big ESLint

This commit is contained in:
Joel Collins 2019-11-11 16:33:43 +00:00
parent 051eabbdc3
commit ebcb938da1
48 changed files with 3890 additions and 2536 deletions

View file

@ -1,25 +1,43 @@
<template>
<div class="uk-margin-horizontal-remove uk-padding-remove">
<div
class="uk-margin-horizontal-remove uk-margin-small-top uk-padding-remove"
>
<div v-if="taskRunning" ref="isPollingElement">
<div class="progress">
<div
v-if="progress"
class="determinate"
:style="barWidthFromProgress"
></div>
<div v-else class="indeterminate"></div>
</div>
<div v-if="taskRunning" ref="isPollingElement">
<div class="progress">
<div v-if="progress" class="determinate" :style="barWidthFromProgress"></div>
<div v-else class="indeterminate"></div>
<button
v-if="canTerminate"
type="button"
class="uk-button uk-button-danger uk-form-small uk-margin uk-float-right uk-width-1-1"
@click="terminateTask()"
>
Terminate
</button>
</div>
<button v-if="canTerminate" type="button" v-on:click="terminateTask()" class="uk-button uk-button-danger uk-form-small uk-margin uk-float-right uk-width-1-1">Terminate</button>
<button
type="button"
:hidden="taskRunning"
class="uk-button uk-button-primary uk-form-small uk-margin uk-float-right uk-width-1-1"
@click="bootstrapTask()"
>
{{ submitLabel }}
</button>
</div>
<button type="button" v-on:click="bootstrapTask()" v-bind:hidden="taskRunning" class="uk-button uk-button-primary uk-form-small uk-margin uk-float-right uk-width-1-1">{{ submitLabel }}</button>
</div>
</template>
<script>
import axios from 'axios'
import axios from "axios";
export default {
name: 'taskSubmitter',
name: "TaskSubmitter",
props: {
submitURL: {
@ -63,148 +81,152 @@ export default {
}
},
data: function () {
data: function() {
return {
taskId: null,
polling: null,
polling: null,
progress: null,
taskRunning: false
};
},
computed: {
barWidthFromProgress: function() {
var progress = this.progress <= 100 ? this.progress : 100;
var styleString = `width: ${progress}%`;
return styleString;
}
},
created() {
},
created() {},
beforeDestroy () {
},
beforeDestroy() {},
methods: {
bootstrapTask: function() {
if (this.requiresConfirmation) {
this.modalConfirm(this.confirmationMessage)
.then(() => {
this.startTask()
}, () => {})
}
else {
this.startTask()
this.modalConfirm(this.confirmationMessage).then(
() => {
this.startTask();
},
() => {}
);
} else {
this.startTask();
}
},
startTask: function() {
console.log("Task start clicked")
this.$emit('submit', this.submitData)
console.log("Task start clicked");
this.$emit("submit", this.submitData);
// Send a request to start a task
axios.post(this.submitURL, this.submitData)
// Get the returned Task ID
.then(response => {
// Fetch the task ID
console.log("Task ID: " + response.data.id)
this.taskId = response.data.id
// Start the store polling TaskId for success
this.taskRunning = true
// Return the poll-task promise (starts polling the task)
return this.pollTask(this.taskId, this.pollTimeout, this.pollInterval)
})
.then(response => {
// Do something with the final response
console.log("Emitting onResponse: ", response)
this.$emit('response', response)
})
.catch(error => {
if (!error) {
error = Error("Unknown error")
}
console.log("Emitting onError: ", error)
this.$emit('error', error)
})
.finally(() => {
console.log("Cleaning up after task.")
// Reset taskRunning and taskId
this.taskRunning = false
this.taskId = null
// Update the form data if we're self-updating
if (this.selfUpdate) {
this.getFormData()
}
})
axios
.post(this.submitURL, this.submitData)
// Get the returned Task ID
.then(response => {
// Fetch the task ID
console.log("Task ID: " + response.data.id);
this.taskId = response.data.id;
// Start the store polling TaskId for success
this.taskRunning = true;
// Return the poll-task promise (starts polling the task)
return this.pollTask(
this.taskId,
this.pollTimeout,
this.pollInterval
);
})
.then(response => {
// Do something with the final response
console.log("Emitting onResponse: ", response);
this.$emit("response", response);
})
.catch(error => {
if (!error) {
error = Error("Unknown error");
}
console.log("Emitting onError: ", error);
this.$emit("error", error);
})
.finally(() => {
console.log("Cleaning up after task.");
// Reset taskRunning and taskId
this.taskRunning = false;
this.taskId = null;
// Update the form data if we're self-updating
if (this.selfUpdate) {
this.getFormData();
}
});
},
pollTask: function(taskId, timeout, interval) {
var endTime = Number(new Date()) + (timeout*1000 || 30000);
interval = interval*1000 || 500;
var endTime = Number(new Date()) + (timeout * 1000 || 30000);
interval = interval * 1000 || 500;
var checkCondition = (resolve, reject) => {
// If the condition is met, we're done!
axios.get(`${this.$store.getters.uri}/task/${taskId}`)
.then(response => {
console.log(response.data.status)
var result = response.data.status
// If the task ends with success
if(result == 'success') {
resolve(response.data)
}
// If task ends with an error
else if (result == 'error') {
// Pass the error string back with reject
reject(new Error(response.data.return))
}
// If task ends with termination
else if (result == 'terminated') {
// Pass a generic termination error back with reject
reject(new Error("Task terminated"))
}
// If task ends in any other way
else if (result != 'running') {
// Pass status string as error
reject(new Error(result))
}
// If the condition isn't met but the timeout hasn't elapsed, go again
else if (Number(new Date()) < endTime) {
// Since the task is still running, we can update the progress bar
this.progress = response.data.progress
// Check again after timeout
setTimeout(checkCondition, interval, resolve, reject)
}
// Didn't match and too much time, reject!
else {
reject(new Error('Polling timed out'))
}
})
// If the condition is met, we're done!
axios
.get(`${this.$store.getters.uri}/task/${taskId}`)
.then(response => {
console.log(response.data.status);
var result = response.data.status;
// If the task ends with success
if (result == "success") {
resolve(response.data);
}
// If task ends with an error
else if (result == "error") {
// Pass the error string back with reject
reject(new Error(response.data.return));
}
// If task ends with termination
else if (result == "terminated") {
// Pass a generic termination error back with reject
reject(new Error("Task terminated"));
}
// If task ends in any other way
else if (result != "running") {
// Pass status string as error
reject(new Error(result));
}
// If the condition isn't met but the timeout hasn't elapsed, go again
else if (Number(new Date()) < endTime) {
// Since the task is still running, we can update the progress bar
this.progress = response.data.progress;
// Check again after timeout
setTimeout(checkCondition, interval, resolve, reject);
}
// Didn't match and too much time, reject!
else {
reject(new Error("Polling timed out"));
}
});
};
return new Promise(checkCondition);
},
pollProgress: function() {
console.log("Starting progress polling")
axios.get(`${this.$store.getters.uri}/task/${this.taskId}`)
.then(response => {
console.log("PROGRESS RESPONSE: ", response.data.progress)
this.progress = response.data.progress
})
console.log("Starting progress polling");
axios
.get(`${this.$store.getters.uri}/task/${this.taskId}`)
.then(response => {
console.log("PROGRESS RESPONSE: ", response.data.progress);
this.progress = response.data.progress;
});
},
terminateTask: function() {
axios.delete(`${this.$store.getters.uri}/task/${this.taskId}`)
.then(response => {
console.log("TERMINATION RESPONSE: ", response.data)
})
},
},
computed: {
barWidthFromProgress: function () {
var progress = ((this.progress <= 100) ? this.progress : 100)
var styleString = `width: ${progress}%`
return styleString
},
axios
.delete(`${this.$store.getters.uri}/task/${this.taskId}`)
.then(response => {
console.log("TERMINATION RESPONSE: ", response.data);
});
}
}
}
};
</script>
<style lang="less" scoped>
@ -219,7 +241,7 @@ export default {
border-radius: 2px;
background-clip: padding-box;
margin: 0.5rem 0 1rem 0;
overflow: hidden;
overflow: hidden;
}
.progress .determinate {
@ -227,88 +249,104 @@ export default {
background-color: inherit;
top: 0;
bottom: 0;
transition: width .3s linear;
transition: width 0.3s linear;
}
.progress .indeterminate, .progress .determinate {
background-color: @global-primary-background;
.progress .indeterminate,
.progress .determinate {
background-color: @global-primary-background;
}
.hook-inverse() {
.progress .indeterminate, .progress .determinate{
background-color: @inverse-primary-muted-color;
}
.progress .indeterminate,
.progress .determinate {
background-color: @inverse-primary-muted-color;
}
}
.progress .indeterminate:before {
content: '';
content: "";
position: absolute;
background-color: inherit;
top: 0;
left: 0;
bottom: 0;
will-change: left, right;
-webkit-animation: indeterminate 2.1s cubic-bezier(0.65, 0.815, 0.735, 0.395) infinite;
animation: indeterminate 2.1s cubic-bezier(0.65, 0.815, 0.735, 0.395) infinite;
-webkit-animation: indeterminate 2.1s cubic-bezier(0.65, 0.815, 0.735, 0.395)
infinite;
animation: indeterminate 2.1s cubic-bezier(0.65, 0.815, 0.735, 0.395) infinite;
}
.progress .indeterminate:after {
content: '';
content: "";
position: absolute;
background-color: inherit;
top: 0;
left: 0;
bottom: 0;
will-change: left, right;
-webkit-animation: indeterminate-short 2.1s cubic-bezier(0.165, 0.84, 0.44, 1) infinite;
animation: indeterminate-short 2.1s cubic-bezier(0.165, 0.84, 0.44, 1) infinite;
-webkit-animation: indeterminate-short 2.1s cubic-bezier(0.165, 0.84, 0.44, 1)
infinite;
animation: indeterminate-short 2.1s cubic-bezier(0.165, 0.84, 0.44, 1)
infinite;
-webkit-animation-delay: 1.15s;
animation-delay: 1.15s;
animation-delay: 1.15s;
}
@-webkit-keyframes indeterminate {
0% {
left: -35%;
right: 100%; }
right: 100%;
}
60% {
left: 100%;
right: -90%; }
right: -90%;
}
100% {
left: 100%;
right: -90%; }
right: -90%;
}
}
@keyframes indeterminate {
0% {
left: -35%;
right: 100%; }
right: 100%;
}
60% {
left: 100%;
right: -90%; }
right: -90%;
}
100% {
left: 100%;
right: -90%; }
right: -90%;
}
}
@-webkit-keyframes indeterminate-short {
0% {
left: -200%;
right: 100%; }
right: 100%;
}
60% {
left: 107%;
right: -8%; }
right: -8%;
}
100% {
left: 107%;
right: -8%; }
right: -8%;
}
}
@keyframes indeterminate-short {
0% {
left: -200%;
right: 100%; }
right: 100%;
}
60% {
left: 107%;
right: -8%; }
right: -8%;
}
100% {
left: 107%;
right: -8%; }
right: -8%;
}
}
</style>
</style>