mirror of
https://github.com/pinry/pinry.git
synced 2025-11-17 10:20:39 +01:00
Feature: Add board edit function (board name could be changed)
This commit is contained in:
committed by
Isaac Bythewood
parent
83413d47f6
commit
3323d8d3c6
@@ -3,27 +3,48 @@
|
|||||||
<form action="">
|
<form action="">
|
||||||
<div class="modal-card" style="width: auto">
|
<div class="modal-card" style="width: auto">
|
||||||
<header class="modal-card-head">
|
<header class="modal-card-head">
|
||||||
<p class="modal-card-title">Board Create</p>
|
<p class="modal-card-title">{{ UIMeta.title }}</p>
|
||||||
</header>
|
</header>
|
||||||
<section class="modal-card-body">
|
<section class="modal-card-body">
|
||||||
|
<div v-if="!isEdit">
|
||||||
<b-field label="Name"
|
<b-field label="Name"
|
||||||
:type="form.name.type"
|
:type="createModel.form.name.type"
|
||||||
:message="form.name.error">
|
:message="createModel.form.name.error">
|
||||||
<b-input
|
<b-input
|
||||||
type="text"
|
type="text"
|
||||||
v-model="form.name.value"
|
v-model="createModel.form.name.value"
|
||||||
placeholder="board name"
|
placeholder="board name"
|
||||||
maxlength="128"
|
maxlength="128"
|
||||||
>
|
>
|
||||||
</b-input>
|
</b-input>
|
||||||
</b-field>
|
</b-field>
|
||||||
|
</div>
|
||||||
|
<div v-if="isEdit">
|
||||||
|
<b-field label="Name"
|
||||||
|
:type="editModel.form.name.type"
|
||||||
|
:message="editModel.form.name.error">
|
||||||
|
<b-input
|
||||||
|
type="text"
|
||||||
|
v-model="editModel.form.name.value"
|
||||||
|
placeholder="board name"
|
||||||
|
maxlength="128"
|
||||||
|
>
|
||||||
|
</b-input>
|
||||||
|
</b-field>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<footer class="modal-card-foot">
|
<footer class="modal-card-foot">
|
||||||
<button class="button" type="button" @click="$parent.close()">Close</button>
|
<button class="button" type="button" @click="$parent.close()">Close</button>
|
||||||
<button
|
<button
|
||||||
|
v-if="!isEdit"
|
||||||
@click="createBoard"
|
@click="createBoard"
|
||||||
class="button is-primary">Create Board
|
class="button is-primary">Create Board
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
v-if="isEdit"
|
||||||
|
@click="saveBoardChanges"
|
||||||
|
class="button is-primary">Save Changes
|
||||||
|
</button>
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@@ -39,23 +60,61 @@ const fields = ['name'];
|
|||||||
export default {
|
export default {
|
||||||
name: 'BoardEditModal',
|
name: 'BoardEditModal',
|
||||||
data() {
|
data() {
|
||||||
const model = ModelForm.fromFields(fields);
|
const createModel = ModelForm.fromFields(fields);
|
||||||
|
const editModel = ModelForm.fromFields(fields);
|
||||||
return {
|
return {
|
||||||
form: model.form,
|
UIMeta: {
|
||||||
helper: model,
|
title: 'Board Create',
|
||||||
|
},
|
||||||
|
createModel,
|
||||||
|
editModel,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
props: {
|
||||||
|
isEdit: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
board: {
|
||||||
|
type: Object,
|
||||||
|
default() {
|
||||||
|
return {};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
if (this.isEdit) {
|
||||||
|
this.UIMeta.title = 'Board Edit';
|
||||||
|
this.editModel.assignToForm(this.board);
|
||||||
|
}
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
saveBoardChanges() {
|
||||||
|
const self = this;
|
||||||
|
const promise = API.Board.saveChanges(
|
||||||
|
this.board.id,
|
||||||
|
this.editModel.asData(),
|
||||||
|
);
|
||||||
|
promise.then(
|
||||||
|
(resp) => {
|
||||||
|
self.$emit('boardSaved', resp);
|
||||||
|
self.$parent.close();
|
||||||
|
},
|
||||||
|
(resp) => {
|
||||||
|
self.editModel.markFieldsAsDanger(resp.data);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
createBoard() {
|
createBoard() {
|
||||||
const self = this;
|
const self = this;
|
||||||
const promise = API.Board.create(this.form.name.value);
|
const promise = API.Board.create(this.createModel.form.name.value);
|
||||||
promise.then(
|
promise.then(
|
||||||
(resp) => {
|
(resp) => {
|
||||||
self.$emit('boardCreated', resp);
|
self.$emit('boardCreated', resp);
|
||||||
self.$parent.close();
|
self.$parent.close();
|
||||||
},
|
},
|
||||||
(resp) => {
|
(resp) => {
|
||||||
self.helper.markFieldsAsDanger(resp.data);
|
self.createModel.markFieldsAsDanger(resp.data);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
v-show="shouldShowEdit(item.id)"
|
v-show="shouldShowEdit(item.id)"
|
||||||
:board="item"
|
:board="item"
|
||||||
v-on:board-delete-succeed="reset"
|
v-on:board-delete-succeed="reset"
|
||||||
|
v-on:board-save-succeed="reset"
|
||||||
></BoardEditorUI>
|
></BoardEditorUI>
|
||||||
<router-link :to="{ name: 'board', params: { boardId: item.id } }">
|
<router-link :to="{ name: 'board', params: { boardId: item.id } }">
|
||||||
<img :src="item.preview_image_url"
|
<img :src="item.preview_image_url"
|
||||||
|
|||||||
@@ -27,6 +27,13 @@ const Board = {
|
|||||||
const url = `${API_PREFIX}boards-auto-complete/?submitter__username=${username}`;
|
const url = `${API_PREFIX}boards-auto-complete/?submitter__username=${username}`;
|
||||||
return axios.get(url);
|
return axios.get(url);
|
||||||
},
|
},
|
||||||
|
saveChanges(boardId, fieldsForm) {
|
||||||
|
const url = `${API_PREFIX}boards/${boardId}/`;
|
||||||
|
return axios.patch(
|
||||||
|
url,
|
||||||
|
fieldsForm,
|
||||||
|
);
|
||||||
|
},
|
||||||
addToBoard(boardId, pinIds) {
|
addToBoard(boardId, pinIds) {
|
||||||
const url = `${API_PREFIX}boards/${boardId}/`;
|
const url = `${API_PREFIX}boards/${boardId}/`;
|
||||||
return axios.patch(
|
return axios.patch(
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
custom-size="mdi-24px">
|
custom-size="mdi-24px">
|
||||||
</b-icon>
|
</b-icon>
|
||||||
</span>
|
</span>
|
||||||
<span class="icon-container">
|
<span class="icon-container" @click="editBoard">
|
||||||
<b-icon
|
<b-icon
|
||||||
type="is-light"
|
type="is-light"
|
||||||
icon="pencil"
|
icon="pencil"
|
||||||
@@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import API from '../api';
|
import API from '../api';
|
||||||
|
import modals from '../modals';
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'BoardEditor',
|
name: 'BoardEditor',
|
||||||
@@ -33,6 +35,16 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
onBoardSaved() {
|
||||||
|
this.$emit('board-save-succeed');
|
||||||
|
},
|
||||||
|
editBoard() {
|
||||||
|
modals.openBoardEdit(
|
||||||
|
this,
|
||||||
|
this.board,
|
||||||
|
this.onBoardSaved,
|
||||||
|
);
|
||||||
|
},
|
||||||
deleteBoard() {
|
deleteBoard() {
|
||||||
this.$buefy.dialog.confirm({
|
this.$buefy.dialog.confirm({
|
||||||
message: 'Delete this Board?',
|
message: 'Delete this Board?',
|
||||||
|
|||||||
@@ -28,6 +28,23 @@ function openBoardCreate(vm) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function openBoardEdit(vm, board, onSaved) {
|
||||||
|
vm.$buefy.modal.open(
|
||||||
|
{
|
||||||
|
parent: vm,
|
||||||
|
component: BoardEdit,
|
||||||
|
props: {
|
||||||
|
board,
|
||||||
|
isEdit: true,
|
||||||
|
},
|
||||||
|
events: {
|
||||||
|
boardSaved: onSaved,
|
||||||
|
},
|
||||||
|
hasModalCard: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function openLogin(vm, onSucceed) {
|
function openLogin(vm, onSucceed) {
|
||||||
vm.$buefy.modal.open({
|
vm.$buefy.modal.open({
|
||||||
parent: vm,
|
parent: vm,
|
||||||
@@ -52,6 +69,7 @@ function openSignUp(vm, onSignUpSucceed) {
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
openBoardCreate,
|
openBoardCreate,
|
||||||
|
openBoardEdit,
|
||||||
openPinCreate,
|
openPinCreate,
|
||||||
openLogin,
|
openLogin,
|
||||||
openSignUp,
|
openSignUp,
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ function FormHelper(form, fields = []) {
|
|||||||
self[fieldName].error = errorMsg;
|
self[fieldName].error = errorMsg;
|
||||||
self[fieldName].type = 'is-danger';
|
self[fieldName].type = 'is-danger';
|
||||||
}
|
}
|
||||||
function markFieldsAsDanger(errorRespObjecct) {
|
function markFieldsAsDanger(errorRespObject) {
|
||||||
Object.entries(errorRespObjecct).forEach(
|
Object.entries(errorRespObject).forEach(
|
||||||
(errorTuple) => {
|
(errorTuple) => {
|
||||||
const [key, error] = errorTuple;
|
const [key, error] = errorTuple;
|
||||||
let msg;
|
let msg;
|
||||||
@@ -38,6 +38,26 @@ function FormHelper(form, fields = []) {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
function asData() {
|
||||||
|
const data = {};
|
||||||
|
Object.entries(form).forEach(
|
||||||
|
(formField) => {
|
||||||
|
const [name, value] = formField;
|
||||||
|
data[name] = value.value;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
function assignToForm(data) {
|
||||||
|
Object.entries(data).forEach(
|
||||||
|
(dataField) => {
|
||||||
|
const [key, value] = dataField;
|
||||||
|
if (key in self) {
|
||||||
|
self[key].value = value;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
function resetAllFields() {
|
function resetAllFields() {
|
||||||
fields.forEach(
|
fields.forEach(
|
||||||
(fieldName) => {
|
(fieldName) => {
|
||||||
@@ -46,11 +66,13 @@ function FormHelper(form, fields = []) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
form,
|
form: self,
|
||||||
fields,
|
fields,
|
||||||
markFieldsAsDanger,
|
markFieldsAsDanger,
|
||||||
markFieldAsDanger,
|
markFieldAsDanger,
|
||||||
resetField,
|
resetField,
|
||||||
|
asData,
|
||||||
|
assignToForm,
|
||||||
resetAllFields,
|
resetAllFields,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user