mirror of
https://github.com/pinry/pinry.git
synced 2025-11-16 09:55:50 +01:00
Feature: PinEdit works well
This commit is contained in:
committed by
Isaac Bythewood
parent
bb4522829d
commit
a7670892f0
@@ -127,8 +127,6 @@ export default {
|
|||||||
onSignUpSucceed() {
|
onSignUpSucceed() {
|
||||||
this.initializeUser(true);
|
this.initializeUser(true);
|
||||||
},
|
},
|
||||||
onPinCreated() {
|
|
||||||
},
|
|
||||||
logOut() {
|
logOut() {
|
||||||
api.User.logOut().then(
|
api.User.logOut().then(
|
||||||
() => {
|
() => {
|
||||||
@@ -140,9 +138,8 @@ export default {
|
|||||||
modals.openLogin(this, this.onLoginSucceed);
|
modals.openLogin(this, this.onLoginSucceed);
|
||||||
},
|
},
|
||||||
createPin() {
|
createPin() {
|
||||||
modals.openPinCreate(
|
modals.openPinEdit(
|
||||||
this,
|
this,
|
||||||
this.onPinCreated,
|
|
||||||
{ username: this.user.meta.username },
|
{ username: this.user.meta.username },
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -92,6 +92,13 @@ const Pin = {
|
|||||||
url,
|
url,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
updateById(pinId, data) {
|
||||||
|
const url = `${API_PREFIX}pins/${pinId}/`;
|
||||||
|
return axios.patch(
|
||||||
|
url,
|
||||||
|
data,
|
||||||
|
);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
custom-size="mdi-24px">
|
custom-size="mdi-24px">
|
||||||
</b-icon>
|
</b-icon>
|
||||||
</span>
|
</span>
|
||||||
<span class="icon-container" v-if="isOwner">
|
<span class="icon-container" v-if="isOwner" @click="editPin">
|
||||||
<b-icon
|
<b-icon
|
||||||
type="is-light"
|
type="is-light"
|
||||||
icon="pencil"
|
icon="pencil"
|
||||||
@@ -90,6 +90,17 @@ export default {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
editPin() {
|
||||||
|
const props = {
|
||||||
|
username: this.currentUsername,
|
||||||
|
existedPin: this.pin,
|
||||||
|
isEdit: true,
|
||||||
|
};
|
||||||
|
modals.openPinEdit(
|
||||||
|
this,
|
||||||
|
props,
|
||||||
|
);
|
||||||
|
},
|
||||||
deletePin() {
|
deletePin() {
|
||||||
this.$buefy.dialog.confirm({
|
this.$buefy.dialog.confirm({
|
||||||
message: 'Delete this Pin?',
|
message: 'Delete this Pin?',
|
||||||
|
|||||||
@@ -5,16 +5,13 @@ import BoardEdit from './BoardEdit.vue';
|
|||||||
import Add2Board from './pin_edit/Add2Board.vue';
|
import Add2Board from './pin_edit/Add2Board.vue';
|
||||||
|
|
||||||
|
|
||||||
function openPinCreate(vm, onCreate, props = null) {
|
function openPinEdit(vm, props = null) {
|
||||||
vm.$buefy.modal.open(
|
vm.$buefy.modal.open(
|
||||||
{
|
{
|
||||||
parent: vm,
|
parent: vm,
|
||||||
component: PinCreateModal,
|
component: PinCreateModal,
|
||||||
props,
|
props,
|
||||||
hasModalCard: true,
|
hasModalCard: true,
|
||||||
events: {
|
|
||||||
'create.succeed': onCreate,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -83,7 +80,7 @@ export default {
|
|||||||
openBoardCreate,
|
openBoardCreate,
|
||||||
openBoardEdit,
|
openBoardEdit,
|
||||||
openAdd2Board,
|
openAdd2Board,
|
||||||
openPinCreate,
|
openPinEdit,
|
||||||
openLogin,
|
openLogin,
|
||||||
openSignUp,
|
openSignUp,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,47 +3,47 @@
|
|||||||
<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">New Pin</p>
|
<p class="modal-card-title">{{ editorMeta.title }}</p>
|
||||||
</header>
|
</header>
|
||||||
<section class="modal-card-body">
|
<section class="modal-card-body">
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<FileUpload
|
<FileUpload
|
||||||
:previewImageURL="createModel.form.url.value"
|
:previewImageURL="pinModel.form.url.value"
|
||||||
v-on:imageUploadSucceed="onUploadDone"
|
v-on:imageUploadSucceed="onUploadDone"
|
||||||
v-on:imageUploadProcessing="onUploadProcessing"
|
v-on:imageUploadProcessing="onUploadProcessing"
|
||||||
></FileUpload>
|
></FileUpload>
|
||||||
</div>
|
</div>
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<b-field label="Image URL"
|
<b-field label="Image URL"
|
||||||
v-show="!disableUrlField"
|
v-show="!disableUrlField && !isEdit"
|
||||||
:type="createModel.form.url.type"
|
:type="pinModel.form.url.type"
|
||||||
:message="createModel.form.url.error">
|
:message="pinModel.form.url.error">
|
||||||
<b-input
|
<b-input
|
||||||
type="text"
|
type="text"
|
||||||
v-model="createModel.form.url.value"
|
v-model="pinModel.form.url.value"
|
||||||
placeholder="where to fetch the image"
|
placeholder="where to fetch the image"
|
||||||
maxlength="256"
|
maxlength="256"
|
||||||
>
|
>
|
||||||
</b-input>
|
</b-input>
|
||||||
</b-field>
|
</b-field>
|
||||||
<b-field label="Image Referer"
|
<b-field label="Image Referer"
|
||||||
:type="createModel.form.referer.type"
|
:type="pinModel.form.referer.type"
|
||||||
:message="createModel.form.referer.error">
|
:message="pinModel.form.referer.error">
|
||||||
<b-input
|
<b-input
|
||||||
type="text"
|
type="text"
|
||||||
v-model="createModel.form.referer.value"
|
v-model="pinModel.form.referer.value"
|
||||||
placeholder="where to find the pin"
|
placeholder="where to find the pin"
|
||||||
maxlength="256"
|
maxlength="256"
|
||||||
>
|
>
|
||||||
</b-input>
|
</b-input>
|
||||||
</b-field>
|
</b-field>
|
||||||
<b-field label="Descripton"
|
<b-field label="Descripton"
|
||||||
:type="createModel.form.description.type"
|
:type="pinModel.form.description.type"
|
||||||
:message="createModel.form.description.error">
|
:message="pinModel.form.description.error">
|
||||||
<b-input
|
<b-input
|
||||||
type="textarea"
|
type="textarea"
|
||||||
v-model="createModel.form.description.value"
|
v-model="pinModel.form.description.value"
|
||||||
placeholder="idea from this pin"
|
placeholder="idea from this pin"
|
||||||
maxlength="1024"
|
maxlength="1024"
|
||||||
>
|
>
|
||||||
@@ -51,14 +51,14 @@
|
|||||||
</b-field>
|
</b-field>
|
||||||
<b-field label="Tags">
|
<b-field label="Tags">
|
||||||
<b-taginput
|
<b-taginput
|
||||||
v-model="createModel.form.tags.value"
|
v-model="pinModel.form.tags.value"
|
||||||
ellipsis
|
ellipsis
|
||||||
icon="label"
|
icon="label"
|
||||||
placeholder="Add a tag">
|
placeholder="Add a tag">
|
||||||
</b-taginput>
|
</b-taginput>
|
||||||
</b-field>
|
</b-field>
|
||||||
</div>
|
</div>
|
||||||
<div class="column">
|
<div class="column" v-if="!isEdit">
|
||||||
<FilterSelect
|
<FilterSelect
|
||||||
:allOptions="boardOptions"
|
:allOptions="boardOptions"
|
||||||
v-on:selected="onSelectBoard"
|
v-on:selected="onSelectBoard"
|
||||||
@@ -69,9 +69,15 @@
|
|||||||
<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="createPin"
|
@click="createPin"
|
||||||
class="button is-primary">Create Pin
|
class="button is-primary">Create Pin
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
v-if="isEdit"
|
||||||
|
@click="savePin"
|
||||||
|
class="button is-primary">Save Changes
|
||||||
|
</button>
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@@ -93,26 +99,49 @@ const fields = ['url', 'referer', 'description', 'tags'];
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'PinCreateModal',
|
name: 'PinCreateModal',
|
||||||
props: ['username'],
|
props: {
|
||||||
|
username: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
isEdit: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
existedPin: {
|
||||||
|
type: Object,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
components: {
|
components: {
|
||||||
FileUpload,
|
FileUpload,
|
||||||
FilterSelect,
|
FilterSelect,
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
const createModel = ModelForm.fromFields(fields);
|
const pinModel = ModelForm.fromFields(fields);
|
||||||
createModel.form.tags.value = [];
|
pinModel.form.tags.value = [];
|
||||||
return {
|
return {
|
||||||
disableUrlField: false,
|
disableUrlField: false,
|
||||||
createModel,
|
pinModel,
|
||||||
formUpload: {
|
formUpload: {
|
||||||
imageId: null,
|
imageId: null,
|
||||||
},
|
},
|
||||||
boardId: null,
|
boardId: null,
|
||||||
boardOptions: [],
|
boardOptions: [],
|
||||||
|
editorMeta: {
|
||||||
|
title: 'New Pin',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.fetchBoardList();
|
this.fetchBoardList();
|
||||||
|
if (this.isEdit) {
|
||||||
|
this.editorMeta.title = 'Edit Pin';
|
||||||
|
this.pinModel.form.url.value = this.existedPin.url;
|
||||||
|
this.pinModel.form.referer.value = this.existedPin.referer;
|
||||||
|
this.pinModel.form.description.value = this.existedPin.description;
|
||||||
|
this.pinModel.form.tags.value = this.existedPin.tags;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
fetchBoardList() {
|
fetchBoardList() {
|
||||||
@@ -141,17 +170,31 @@ export default {
|
|||||||
onUploadDone(imageId) {
|
onUploadDone(imageId) {
|
||||||
this.formUpload.imageId = imageId;
|
this.formUpload.imageId = imageId;
|
||||||
},
|
},
|
||||||
|
savePin() {
|
||||||
|
const self = this;
|
||||||
|
const data = this.pinModel.asDataByFields(
|
||||||
|
['referer', 'description', 'tags'],
|
||||||
|
);
|
||||||
|
const promise = API.Pin.updateById(this.existedPin.id, data);
|
||||||
|
promise.then(
|
||||||
|
(resp) => {
|
||||||
|
bus.bus.$emit(bus.events.refreshPin);
|
||||||
|
self.$emit('pinUpdated', resp);
|
||||||
|
self.$parent.close();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
createPin() {
|
createPin() {
|
||||||
const self = this;
|
const self = this;
|
||||||
let promise;
|
let promise;
|
||||||
if (isURLBlank(this.createModel.form.url.value) && this.formUpload.imageId === null) {
|
if (isURLBlank(this.pinModel.form.url.value) && this.formUpload.imageId === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.formUpload.imageId === null) {
|
if (this.formUpload.imageId === null) {
|
||||||
const data = this.createModel.asDataByFields(fields);
|
const data = this.pinModel.asDataByFields(fields);
|
||||||
promise = API.Pin.createFromURL(data);
|
promise = API.Pin.createFromURL(data);
|
||||||
} else {
|
} else {
|
||||||
const data = this.createModel.asDataByFields(
|
const data = this.pinModel.asDataByFields(
|
||||||
['referer', 'description', 'tags'],
|
['referer', 'description', 'tags'],
|
||||||
);
|
);
|
||||||
data.image_by_id = this.formUpload.imageId;
|
data.image_by_id = this.formUpload.imageId;
|
||||||
|
|||||||
Reference in New Issue
Block a user