Skip to content

Commit

Permalink
finish submission form, just have github left
Browse files Browse the repository at this point in the history
  • Loading branch information
3vorp committed Jan 19, 2024
1 parent 5a9948f commit 6bd7291
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 65 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
},
"homepage": "https://github.com/Faithful-Resource-Pack/App#readme",
"dependencies": {
"axios": "^1.6.3",
"axios": "^1.6.5",
"btoa": "^1.2.1",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"moment": "^2.30.1",
"node-domexception": "^2.0.1",
"node-fetch": "^3.3.2",
"node-localstorage": "^3.0.5",
"prettier": "^3.1.1",
"prettier": "^3.2.4",
"twin-bcrypt": "^2.1.1",
"url": "^0.11.3"
},
Expand All @@ -43,7 +43,7 @@
"cors": "^2.8.5",
"env-cmd": "^10.1.0",
"mocha": "^10.2.0",
"nodemon": "^3.0.2",
"puppeteer": "^21.6.1"
"nodemon": "^3.0.3",
"puppeteer": "^21.7.0"
}
}
3 changes: 2 additions & 1 deletion pages/pack/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
name: "pack-page",
components: {
"pack-creator": PackCreator,
"pack-remove-confirm": PackRemoveConfirm
"pack-remove-confirm": PackRemoveConfirm,
},
template: `
<v-container>
Expand Down Expand Up @@ -155,6 +155,7 @@ export default {
},
disableDialog(refresh = false) {
this.dialogOpen = false;
// clear form
this.dialogData = {};
if (refresh) this.startSearch();
},
Expand Down
21 changes: 13 additions & 8 deletions pages/pack/pack_creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
name: "pack-creator",
components: {
submissionCreator,
packRemoveConfirm
packRemoveConfirm,
},
template: `
<v-dialog v-model="dialog" content-class="colored" max-width="600">
Expand Down Expand Up @@ -40,7 +40,7 @@ export default {
<v-text-field :color="color" required clearable v-model="formData.name" :label="$root.lang().database.labels.pack_name"></v-text-field>
<v-select :color="color" :item-color="color" required multiple deletable-chips small-chips v-model="formData.tags" :items="tags" :label="$root.lang().database.labels.pack_tags"></v-select>
<v-text-field :color="color" required type="number" v-model="formData.resolution" :label="$root.lang().database.labels.pack_resolution"></v-text-field>
<v-text-field :color="color" required :rules="downloadLinkRules" clearable v-model="formData.logo" :label="$root.lang().database.labels.pack_logo"></v-text-field>
<v-text-field :color="color" :rules="downloadLinkRules" clearable v-model="formData.logo" :label="$root.lang().database.labels.pack_logo"></v-text-field>
<h2 class="title">{{ $root.lang().database.subtitles.submissions }}</h2>
<div v-if="Object.keys(formData.submission).length">
<v-container>
Expand Down Expand Up @@ -132,7 +132,7 @@ export default {
id: "",
name: "",
confirm: false,
}
},
};
},
methods: {
Expand All @@ -145,6 +145,13 @@ export default {
};
else this.submissionData = data.submission;
},
disableSubmission() {
this.submissionOpen = false;
// clear form
this.submissionData = {};
if (!this.add) this.getSubmission(this.formData.id);
this.$forceUpdate();
},
getSubmission(packID) {
axios
.get(`${this.$root.apiURL}/submissions/${packID}`)
Expand All @@ -154,11 +161,6 @@ export default {
this.formData.submission = res.data;
});
},
disableSubmission() {
this.submissionOpen = false;
if (!this.add) this.getSubmission(this.formData.id);
this.$forceUpdate();
},
deleteSubmission() {
if (this.add) {
// reset directly, no need for confirmation modal
Expand Down Expand Up @@ -195,6 +197,9 @@ export default {
if (!data.id) delete data.id;
}

// stop accidental casting
if (!data.logo) data.logo = null;

// only add submission property if filled out
if (
!this.submissionAdd || // if changing submission, already done separately
Expand Down
2 changes: 1 addition & 1 deletion pages/pack/pack_remove_confirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default {
type: {
type: String,
required: true,
}
},
},
methods: {
deletePack() {
Expand Down
131 changes: 112 additions & 19 deletions pages/pack/submission_creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,76 @@ export default {
</v-select>
<v-container>
<v-row>
<v-checkbox :color="color" v-model="formData.council_enabled" :label="$root.lang().database.labels.council_enabled"></v-checkbox>
<v-col>
<v-text-field
:color="color"
persistent-hint
clearable
required
:hint="$root.lang().database.hints.submission_timings"
v-model="formData.time_to_results"
:label="$root.lang().database.labels.time_to_results"
/>
</v-col>
<v-col v-if="formData.council_enabled">
<v-text-field
:color="color"
persistent-hint
clearable
required
:hint="$root.lang().database.hints.submission_timings"
v-model="formData.time_to_council"
:label="$root.lang().database.labels.time_to_council"
/>
</v-col>
</v-row>
<v-row>
<v-col>
<v-checkbox
:color="color"
v-model="formData.council_enabled"
:label="$root.lang().database.labels.council_enabled"
/>
</v-col>
<v-col>
<v-text-field
:color="color"
clearable
v-model="formData.contributor_role"
:label="$root.lang().database.labels.contributor_role"
/>
</v-col>
</v-row>
<h2 class="title">{{ $root.lang().database.subtitles.channels }}</h2>
<p class="text-caption">{{ $root.lang().database.hints.channel_ids }}</p>
<v-row>
<v-col>
<v-text-field
:color="color"
required
clearable
v-model="formData.channels.submit"
:label="$root.lang().database.labels.channels.submit"
/>
</v-col>
<v-col v-if="formData.council_enabled">
<v-text-field
:color="color"
required
clearable
v-model="formData.channels.council"
:label="$root.lang().database.labels.channels.council"
/>
</v-col>
<v-col>
<v-text-field
:color="color"
required
clearable
v-model="formData.channels.results"
:label="$root.lang().database.labels.channels.results"
/>
</v-col>
</v-row>
</v-container>
</v-form>
Expand Down Expand Up @@ -89,36 +158,46 @@ export default {
return {
formValid: false,
formData: {
id: "",
reference: "",
council_enabled: "",
id: null,
reference: null,
council_enabled: null,
channels: {
submit: "",
council: "",
results: "",
submit: null,
council: null,
results: null,
},
time_to_council: 0,
time_to_results: 0,
contributor_role: "",
time_to_council: null,
time_to_results: null,
contributor_role: null,
},
packs: [],
};
},
methods: {
send() {
// all pack info is added in one big request on creation so we beam it back
const data = { ...this.formData };

if (!data.council_enabled) {
// delete properties that may have been shown and hidden at some point
delete data.channels.council;
delete data.time_to_council;
}

// get rid of empty strings so api can validate properly
if (!data.contributor_role) delete data.contributor_role;
Object.entries(data.channels).forEach(([k, v]) => {
if (!v) data.channels[k] = null;
});

// all pack info is added in one big request on creation so we "beam" it back
if (this.first) {
this.$emit("submissionFinished", this.formData);
this.$emit("submissionFinished", data);
return this.disableDialog();
}

const requestPromise = this.add
? axios.post(`${this.$root.apiURL}/submissions`, this.formData, this.$root.apiOptions)
: axios.put(
`${this.$root.apiURL}/submissions/${this.formData.id}`,
this.formData,
this.$root.apiOptions,
);
? axios.post(`${this.$root.apiURL}/submissions`, data, this.$root.apiOptions)
: axios.put(`${this.$root.apiURL}/submissions/${data.id}`, data, this.$root.apiOptions);

requestPromise
.then(() => {
Expand All @@ -142,6 +221,7 @@ export default {
},
},
created() {
console.log(this.formData);
axios.get(`${this.$root.apiURL}/packs/raw`).then((res) => {
this.packs = Object.values(res.data);
});
Expand All @@ -156,7 +236,20 @@ export default {
this.formData[k] = v;
}
} else {
this.$refs.form.reset();
// reset form on init
this.formData = {
id: null,
reference: null,
council_enabled: null,
channels: {
submit: null,
council: null,
results: null,
},
time_to_council: null,
time_to_results: null,
contributor_role: null,
};
if (this.data.id) this.formData.id = this.data.id;
}
});
Expand Down
Loading

0 comments on commit 6bd7291

Please sign in to comment.