Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented: Add additional job actions to job config component(#364tt29) #216

Merged
merged 8 commits into from
Aug 26, 2022
108 changes: 103 additions & 5 deletions src/components/JobConfiguration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,34 @@
<ion-button expand="block" @click="saveChanges()">{{ $t("Save changes") }}</ion-button>
</div>
</section>
<div class="more-actions">
<ion-item @click="viewJobHistory(currentJob)" button>
<ion-icon slot="start" :icon="timeOutline" />
{{ $t("History") }}
</ion-item>
<ion-item @click="runNow(title, currentJob)" button>
<ion-icon slot="start" :icon="flashOutline" />
{{ $t("Run now") }}
</ion-item>
<ion-item @click="copyJobInformation(currentJob)" button>
<ion-icon slot="start" :icon="copyOutline" />
{{ $t("Copy details") }}
</ion-item>
<ion-item @click="updatePinnedJobs(currentJob?.systemJobEnumId)" button>
<ion-icon slot="start" :icon="pinOutline" />
{{ $t("Pin job") }}
<ion-checkbox slot="end" :checked="pinnedJobs && pinnedJobs.includes(currentJob.systemJobEnumId)" />
</ion-item>
</div>

</template>

<script lang="ts">
import { defineComponent } from "vue";
import {
IonBadge,
IonButton,
IonCheckbox,
IonContent,
IonDatetime,
IonIcon,
Expand All @@ -86,15 +107,21 @@ import {
IonModal,
IonSelect,
IonSelectOption,
alertController
alertController,
modalController,
} from "@ionic/vue";
import {
calendarClearOutline,
flashOutline,
copyOutline,
timeOutline,
timerOutline,
syncOutline,
personCircleOutline
personCircleOutline,
pinOutline,
} from "ionicons/icons";
import JobHistoryModal from '@/components/JobHistoryModal.vue'
import { Plugins } from '@capacitor/core';
import { handleDateTimeInput, showToast } from "@/utils";
import { mapGetters, useStore } from "vuex";
import { DateTime } from 'luxon';
Expand All @@ -115,7 +142,8 @@ export default defineComponent({
IonList,
IonModal,
IonSelect,
IonSelectOption
IonSelectOption,
IonCheckbox
},
data() {
return {
Expand All @@ -127,6 +155,9 @@ export default defineComponent({
props: ["title", "status", "type"],
computed: {
...mapGetters({
getEnumDescription: 'job/getEnumDescription',
getEnumName: 'job/getEnumName',
pinnedJobs: 'user/getPinnedJobs',
getJobStatus: 'job/getJobStatus',
getJob: 'job/getJob',
shopifyConfigId: 'user/getShopifyConfigId',
Expand Down Expand Up @@ -286,6 +317,60 @@ export default defineComponent({
if (job) {
job.runTime = handleDateTimeInput(ev['detail'].value)
}
},
async viewJobHistory(job: any) {
const jobHistoryModal = await modalController.create({
component: JobHistoryModal,
componentProps: { currentJob: job }
});
await jobHistoryModal.present();
jobHistoryModal.onDidDismiss().then(() => {
jobHistoryModal.dismiss({ dismissed: true });
})
},
async runNow(header: string, job: any) {
const jobAlert = await alertController
.create({
header,
message: this.$t('This job will be scheduled to run as soon as possible. There may not be enough time to revert this action.', {space: '<br/><br/>'}),
buttons: [
{
text: this.$t("Cancel"),
role: 'cancel',
},
{
text: this.$t('Run now'),
handler: () => {
if (job) {
this.store.dispatch('job/runServiceNow', job)
}
}
}
]
});

return jobAlert.present();
},
async copyJobInformation(job: any) {
const { Clipboard } = Plugins;
const jobDetails = `jobId: ${job.jobId}, jobName: ${this.getEnumName(job.systemJobEnumId)}, jobDescription: ${this.getEnumDescription(job.systemJobEnumId)}`;

await Clipboard.write({
string: jobDetails
}).then(() => {
showToast(this.$t("Copied job details to clipboard"));
})
},
async updatePinnedJobs(enumId: any) {
const pinnedJobs = new Set(this.pinnedJobs);
if(pinnedJobs.has(enumId)) {
pinnedJobs.delete(enumId);
await this.store.dispatch('user/updatePinnedJobs', { pinnedJobs: [...pinnedJobs] });
emitter.emit("pinnedJobsUpdated", enumId);
} else {
pinnedJobs.add(enumId);
await this.store.dispatch('user/updatePinnedJobs', { pinnedJobs: [...pinnedJobs] });
}
}
},
setup() {
Expand All @@ -294,12 +379,15 @@ export default defineComponent({

return {
calendarClearOutline,
copyOutline,
flashOutline,
timeOutline,
timerOutline,
store,
router,
syncOutline,
personCircleOutline
personCircleOutline,
pinOutline
};
}
});
Expand Down Expand Up @@ -328,7 +416,17 @@ ion-list {

.mobile-only {
display: none;
}
}
.more-actions {
display: flex;
flex-wrap: wrap;
align-items: end;
row-gap: var(--spacer-sm);
margin-top: var(--spacer-sm);
}
.more-actions > * {
flex-basis: 50%;
}
}

ion-label:nth-child(3) {
Expand Down