feat(schedule): don't show repo commit check schedules

This commit is contained in:
fiftin 2024-06-23 23:59:14 +05:00
parent 477c0dfe7d
commit b511385465
No known key found for this signature in database
GPG Key ID: 044381366A5D4731
4 changed files with 80 additions and 38 deletions

View File

@ -32,7 +32,10 @@ func (d *BoltDb) getProjectSchedules(projectID int) (schedules []db.Schedule, er
}
func (d *BoltDb) GetProjectSchedules(projectID int) (schedules []db.ScheduleWithTpl, err error) {
err = d.getObjects(projectID, db.ScheduleProps, db.RetrieveQueryParams{}, nil, &schedules)
err = d.getObjects(projectID, db.ScheduleProps, db.RetrieveQueryParams{}, func(referringObj interface{}) bool {
s := referringObj.(db.ScheduleWithTpl)
return s.RepositoryID == nil
}, &schedules)
return
}

View File

@ -76,7 +76,7 @@ func (d *SqlDb) GetProjectSchedules(projectID int) (schedules []db.ScheduleWithT
_, err = d.selectAll(&schedules,
"SELECT ps.*, pt.name as tpl_name FROM project__schedule ps "+
"JOIN project__template pt ON pt.id = ps.template_id "+
"WHERE ps.project_id=?",
"WHERE ps.repository_id IS NULL AND ps.project_id=?",
projectID)
return
}

View File

@ -238,34 +238,16 @@
dense
></v-select>
<v-row>
<v-col cols="5" class="pr-1">
<v-text-field
style="font-size: 14px"
v-model="cronFormat"
:label="$t('cron')"
:disabled="formSaving"
placeholder="* * * * *"
v-if="schedules == null || schedules.length <= 1"
outlined
dense
hide-details
></v-text-field>
</v-col>
<v-checkbox
class="mt-0"
:label="$t('iWantToRunATaskByTheCronOnlyForForNewCommitsOfSome')"
v-model="cronRepositoryIdVisible"
/>
<v-row v-if="cronRepositoryIdVisible" class="mb-2">
<v-col cols="7">
<a
v-if="!cronRepositoryIdVisible && cronRepositoryId == null"
@click="cronRepositoryIdVisible = true"
class="text-caption d-block"
style="line-height: 1.1;"
>
{{ $t('iWantToRunATaskByTheCronOnlyForForNewCommitsOfSome') }}
</a>
<v-select
style="font-size: 14px"
v-if="cronRepositoryIdVisible || cronRepositoryId != null"
v-model="cronRepositoryId"
:label="$t('repository2')"
:placeholder="$t('cronChecksNewCommitBeforeRun')"
@ -278,16 +260,24 @@
dense
hide-details
></v-select>
</v-col>
<v-col cols="5">
<v-select
v-model="cronFormat"
:label="$t('Interval')"
:placeholder="$t('New commit check interval')"
item-value="cron"
item-text="title"
:items="cronFormats"
:disabled="formSaving"
outlined
dense
hide-details
/>
</v-col>
</v-row>
<small class="mt-1 mb-4 d-block">
{{ $t('readThe') }}
<a target="_blank" href="https://pkg.go.dev/github.com/robfig/cron/v3#hdr-CRON_Expression_Format">{{ $t('docs') }}</a>
{{ $t('toLearnMoreAboutCron') }}
</small>
<v-checkbox
class="mt-0"
:label="$t('suppressSuccessAlerts')"
@ -356,6 +346,22 @@ export default {
data() {
return {
cronFormats: [{
cron: '* * * * *',
title: '1 minute',
}, {
cron: '*/5 * * * *',
title: '5 minutes',
}, {
cron: '*/10 * * * *',
title: '10 minutes',
}, {
cron: '@hourly',
title: '1 hour',
}, {
cron: '@daily',
title: '24 hours',
}],
itemTypeIndex: 0,
TEMPLATE_TYPE_ICONS,
TEMPLATE_TYPE_TITLES,
@ -517,9 +523,13 @@ export default {
responseType: 'json',
})).data;
if (this.schedules.length === 1) {
this.cronFormat = this.schedules[0].cron_format;
this.cronRepositoryId = this.schedules[0].repository_id;
if (this.schedules.length > 0) {
const schedule = this.schedules.find((s) => s.repository_id != null);
if (schedule != null) {
this.cronFormat = schedule.cron_format;
this.cronRepositoryId = schedule.repository_id;
this.cronRepositoryIdVisible = this.cronRepositoryId != null;
}
}
this.itemTypeIndex = Object.keys(TEMPLATE_TYPE_ICONS).indexOf(this.item.type);
@ -566,7 +576,7 @@ export default {
}
} else if (this.schedules.length > 1) {
// do nothing
} else if (this.cronFormat == null || this.cronFormat === '') {
} else if (this.cronFormat == null || this.cronFormat === '' || !this.cronRepositoryIdVisible) {
// drop schedule
await axios({
method: 'delete',

View File

@ -52,6 +52,16 @@
class="mt-4"
:items-per-page="Number.MAX_VALUE"
>
<template v-slot:item.tpl_name="{ item }">
<div class="d-flex">
<router-link :to="
'/project/' + item.project_id +
'/templates/' + item.template_id"
>{{ item.tpl_name }}
</router-link>
</div>
</template>
<template v-slot:item.actions="{ item }">
<div style="white-space: nowrap">
<v-btn
@ -71,6 +81,20 @@
</v-btn>
</div>
</template>
<template v-slot:expanded-item="{ headers, item }">
<td
:colspan="headers.length"
v-if="openedItems.some((template) => template.id === item.id)"
>
<TaskList
style="border: 1px solid lightgray; border-radius: 6px; margin: 10px 0;"
:template="item"
:limit="5"
:hide-footer="true"
/>
</td>
</template>
</v-data-table>
</div>
@ -78,16 +102,21 @@
<script>
import ItemListPageBase from '@/components/ItemListPageBase';
import ScheduleForm from '@/components/ScheduleForm.vue';
import TaskList from '@/components/TaskList.vue';
export default {
components: { ScheduleForm },
components: { TaskList, ScheduleForm },
mixins: [ItemListPageBase],
data() {
return {
openedItems: [],
};
},
methods: {
getHeaders() {
return [{
text: this.$i18n.t('Cron'),
value: 'cron_format',
width: '100%',
}, {
text: this.$i18n.t('Template'),
value: 'tpl_name',