mirror of
https://github.com/semaphoreui/semaphore.git
synced 2025-01-20 15:29:28 +01:00
fix(web): schedule form
This commit is contained in:
parent
33a9b0d730
commit
477c0dfe7d
@ -42,6 +42,17 @@ func GetSchedule(w http.ResponseWriter, r *http.Request) {
|
||||
helpers.WriteJSON(w, http.StatusOK, schedule)
|
||||
}
|
||||
|
||||
func GetProjectSchedules(w http.ResponseWriter, r *http.Request) {
|
||||
project := context.Get(r, "project").(db.Project)
|
||||
|
||||
tplSchedules, err := helpers.Store(r).GetProjectSchedules(project.ID)
|
||||
if err != nil {
|
||||
helpers.WriteError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
helpers.WriteJSON(w, http.StatusOK, tplSchedules)
|
||||
}
|
||||
func GetTemplateSchedules(w http.ResponseWriter, r *http.Request) {
|
||||
project := context.Get(r, "project").(db.Project)
|
||||
templateID, err := helpers.GetIntParam("template_id", w, r)
|
||||
|
@ -178,6 +178,7 @@ func Route() *mux.Router {
|
||||
projectUserAPI.Path("/templates").HandlerFunc(projects.GetTemplates).Methods("GET", "HEAD")
|
||||
projectUserAPI.Path("/templates").HandlerFunc(projects.AddTemplate).Methods("POST")
|
||||
|
||||
projectUserAPI.Path("/schedules").HandlerFunc(projects.GetProjectSchedules).Methods("GET", "HEAD")
|
||||
projectUserAPI.Path("/schedules").HandlerFunc(projects.AddSchedule).Methods("POST")
|
||||
projectUserAPI.Path("/schedules/validate").HandlerFunc(projects.ValidateScheduleCronFormat).Methods("POST")
|
||||
|
||||
|
@ -8,3 +8,8 @@ type Schedule struct {
|
||||
RepositoryID *int `db:"repository_id" json:"repository_id"`
|
||||
LastCommitHash *string `db:"last_commit_hash" json:"-"`
|
||||
}
|
||||
|
||||
type ScheduleWithTpl struct {
|
||||
Schedule
|
||||
TemplateName string `db:"tpl_name" json:"tpl_name"`
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ type Store interface {
|
||||
DeleteTemplate(projectID int, templateID int) error
|
||||
|
||||
GetSchedules() ([]Schedule, error)
|
||||
GetProjectSchedules(projectID int) ([]Schedule, error)
|
||||
GetProjectSchedules(projectID int) ([]ScheduleWithTpl, error)
|
||||
GetTemplateSchedules(projectID int, templateID int) ([]Schedule, error)
|
||||
CreateSchedule(schedule Schedule) (Schedule, error)
|
||||
UpdateSchedule(schedule Schedule) error
|
||||
|
@ -16,7 +16,7 @@ func (d *BoltDb) GetSchedules() (schedules []db.Schedule, err error) {
|
||||
|
||||
for _, proj := range allProjects {
|
||||
var projSchedules []db.Schedule
|
||||
projSchedules, err = d.GetProjectSchedules(proj.ID)
|
||||
projSchedules, err = d.getProjectSchedules(proj.ID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -26,7 +26,12 @@ func (d *BoltDb) GetSchedules() (schedules []db.Schedule, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (d *BoltDb) GetProjectSchedules(projectID int) (schedules []db.Schedule, err error) {
|
||||
func (d *BoltDb) getProjectSchedules(projectID int) (schedules []db.Schedule, err error) {
|
||||
err = d.getObjects(projectID, db.ScheduleProps, db.RetrieveQueryParams{}, nil, &schedules)
|
||||
return
|
||||
}
|
||||
|
||||
func (d *BoltDb) GetProjectSchedules(projectID int) (schedules []db.ScheduleWithTpl, err error) {
|
||||
err = d.getObjects(projectID, db.ScheduleProps, db.RetrieveQueryParams{}, nil, &schedules)
|
||||
return
|
||||
}
|
||||
@ -34,7 +39,7 @@ func (d *BoltDb) GetProjectSchedules(projectID int) (schedules []db.Schedule, er
|
||||
func (d *BoltDb) GetTemplateSchedules(projectID int, templateID int) (schedules []db.Schedule, err error) {
|
||||
schedules = make([]db.Schedule, 0)
|
||||
|
||||
projSchedules, err := d.GetProjectSchedules(projectID)
|
||||
projSchedules, err := d.getProjectSchedules(projectID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -72,9 +72,11 @@ func (d *SqlDb) GetSchedules() (schedules []db.Schedule, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (d *SqlDb) GetProjectSchedules(projectID int) (schedules []db.Schedule, err error) {
|
||||
func (d *SqlDb) GetProjectSchedules(projectID int) (schedules []db.ScheduleWithTpl, err error) {
|
||||
_, err = d.selectAll(&schedules,
|
||||
"select * from project__schedule where project_id=?",
|
||||
"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=?",
|
||||
projectID)
|
||||
return
|
||||
}
|
||||
|
@ -561,7 +561,7 @@
|
||||
.v-data-table-header {
|
||||
}
|
||||
|
||||
.theme--light.v-data-table > .v-data-table__wrapper > table > thead > tr:last-child > th {
|
||||
.v-data-table > .v-data-table__wrapper > table > thead > tr:last-child > th {
|
||||
text-transform: uppercase;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
80
web/src/components/ScheduleForm.vue
Normal file
80
web/src/components/ScheduleForm.vue
Normal file
@ -0,0 +1,80 @@
|
||||
<template>
|
||||
<v-form
|
||||
ref="form"
|
||||
lazy-validation
|
||||
v-model="formValid"
|
||||
v-if="templates && item != null"
|
||||
>
|
||||
|
||||
<v-alert
|
||||
:value="formError"
|
||||
color="error"
|
||||
class="pb-2"
|
||||
>{{ formError }}</v-alert>
|
||||
|
||||
<!-- <v-text-field-->
|
||||
<!-- v-model="item.name"-->
|
||||
<!-- :label="$t('Name')"-->
|
||||
<!-- :rules="[v => !!v || $t('name_required')]"-->
|
||||
<!-- required-->
|
||||
<!-- :disabled="formSaving"-->
|
||||
<!-- class="mb-4"-->
|
||||
<!-- ></v-text-field>-->
|
||||
|
||||
<v-select
|
||||
v-model="item.template_id"
|
||||
:label="$t('Template')"
|
||||
:items="templates"
|
||||
item-value="id"
|
||||
:item-text="(itm) => itm.name"
|
||||
:rules="[v => !!v || $t('template_required')]"
|
||||
required
|
||||
:disabled="formSaving"
|
||||
/>
|
||||
|
||||
<v-text-field
|
||||
v-model="item.cron_format"
|
||||
:label="$t('Cron')"
|
||||
:rules="[v => !!v || $t('Cron required')]"
|
||||
required
|
||||
:disabled="formSaving"
|
||||
class="mb-4"
|
||||
></v-text-field>
|
||||
|
||||
</v-form>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import ItemFormBase from '@/components/ItemFormBase';
|
||||
import axios from 'axios';
|
||||
|
||||
export default {
|
||||
mixins: [ItemFormBase],
|
||||
|
||||
data() {
|
||||
return {
|
||||
templates: null,
|
||||
};
|
||||
},
|
||||
|
||||
async created() {
|
||||
this.templates = (await axios({
|
||||
method: 'get',
|
||||
url: `/api/project/${this.projectId}/templates`,
|
||||
responseType: 'json',
|
||||
})).data;
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
||||
getItemsUrl() {
|
||||
return `/api/project/${this.projectId}/schedules`;
|
||||
},
|
||||
|
||||
getSingleItemUrl() {
|
||||
return `/api/project/${this.projectId}/schedules/${this.itemId}`;
|
||||
},
|
||||
|
||||
},
|
||||
};
|
||||
</script>
|
@ -3,12 +3,12 @@
|
||||
<EditDialog
|
||||
v-model="editDialog"
|
||||
:save-button-text="$t('save')"
|
||||
:title="$t('editEnvironment')"
|
||||
:title="$t('Edit Schedule')"
|
||||
:max-width="500"
|
||||
@save="loadItems"
|
||||
>
|
||||
<template v-slot:form="{ onSave, onError, needSave, needReset }">
|
||||
<EnvironmentForm
|
||||
<ScheduleForm
|
||||
:project-id="projectId"
|
||||
:item-id="itemId"
|
||||
@save="onSave"
|
||||
@ -20,14 +20,14 @@
|
||||
</EditDialog>
|
||||
|
||||
<ObjectRefsDialog
|
||||
object-title="environment"
|
||||
object-title="schedule"
|
||||
:object-refs="itemRefs"
|
||||
:project-id="projectId"
|
||||
v-model="itemRefsDialog"
|
||||
/>
|
||||
|
||||
<YesNoDialog
|
||||
:title="$t('deleteEnvironment')"
|
||||
:title="$t('Delete Schedule')"
|
||||
:text="$t('askDeleteEnv')"
|
||||
v-model="deleteItemDialog"
|
||||
@yes="deleteItem(itemId)"
|
||||
@ -35,13 +35,13 @@
|
||||
|
||||
<v-toolbar flat >
|
||||
<v-app-bar-nav-icon @click="showDrawer()"></v-app-bar-nav-icon>
|
||||
<v-toolbar-title>{{ $t('environment2') }}</v-toolbar-title>
|
||||
<v-toolbar-title>{{ $t('Schedule') }}</v-toolbar-title>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn
|
||||
color="primary"
|
||||
@click="editItem('new')"
|
||||
v-if="can(USER_PERMISSIONS.manageProjectResources)"
|
||||
>{{ $t('newEnvironment') }}
|
||||
>{{ $t('New Schedule') }}
|
||||
</v-btn>
|
||||
</v-toolbar>
|
||||
|
||||
@ -77,32 +77,35 @@
|
||||
</template>
|
||||
<script>
|
||||
import ItemListPageBase from '@/components/ItemListPageBase';
|
||||
import EnvironmentForm from '@/components/EnvironmentForm.vue';
|
||||
import ScheduleForm from '@/components/ScheduleForm.vue';
|
||||
|
||||
export default {
|
||||
components: { EnvironmentForm },
|
||||
components: { ScheduleForm },
|
||||
mixins: [ItemListPageBase],
|
||||
methods: {
|
||||
getHeaders() {
|
||||
return [{
|
||||
text: this.$i18n.t('name'),
|
||||
value: 'name',
|
||||
text: this.$i18n.t('Cron'),
|
||||
value: 'cron_format',
|
||||
width: '100%',
|
||||
},
|
||||
{
|
||||
}, {
|
||||
text: this.$i18n.t('Template'),
|
||||
value: 'tpl_name',
|
||||
width: '100%',
|
||||
}, {
|
||||
text: this.$i18n.t('actions'),
|
||||
value: 'actions',
|
||||
sortable: false,
|
||||
}];
|
||||
},
|
||||
getItemsUrl() {
|
||||
return `/api/project/${this.projectId}/environment`;
|
||||
return `/api/project/${this.projectId}/schedules`;
|
||||
},
|
||||
getSingleItemUrl() {
|
||||
return `/api/project/${this.projectId}/environment/${this.itemId}`;
|
||||
return `/api/project/${this.projectId}/schedules/${this.itemId}`;
|
||||
},
|
||||
getEventName() {
|
||||
return 'i-environment';
|
||||
return 'i-schedule';
|
||||
},
|
||||
},
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user