mirror of
https://github.com/pinry/pinry.git
synced 2025-11-17 10:20:39 +01:00
Feature: Add2Board with board creation works well
This commit is contained in:
committed by
Isaac Bythewood
parent
6cc78423a8
commit
4a33fd806a
@@ -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);
|
||||||
},
|
},
|
||||||
|
addToBoard(boardId, pinIds) {
|
||||||
|
const url = `${API_PREFIX}boards/${boardId}/`;
|
||||||
|
return axios.patch(
|
||||||
|
url,
|
||||||
|
{ pins_to_add: pinIds },
|
||||||
|
);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const Pin = {
|
const Pin = {
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="filter-select">
|
<div class="filter-select">
|
||||||
<b-field label="Select Board"
|
<b-field label="Select Board"
|
||||||
:type="form.board.type"
|
:type="form.name.type"
|
||||||
:message="form.board.error">
|
:message="form.name.error">
|
||||||
<b-input
|
<b-input
|
||||||
type="text"
|
type="text"
|
||||||
v-model="form.board.value"
|
v-model="form.name.value"
|
||||||
placeholder="Type to filter or Create one"
|
placeholder="Type to filter or Create one"
|
||||||
maxlength="128"
|
maxlength="128"
|
||||||
>
|
>
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
import API from '../api';
|
import API from '../api';
|
||||||
import ModelForm from '../utils/ModelForm';
|
import ModelForm from '../utils/ModelForm';
|
||||||
|
|
||||||
const fields = ['board'];
|
const fields = ['name'];
|
||||||
|
|
||||||
function getFilteredOptions(options, filterText) {
|
function getFilteredOptions(options, filterText) {
|
||||||
return options.filter(
|
return options.filter(
|
||||||
@@ -83,14 +83,14 @@ export default {
|
|||||||
},
|
},
|
||||||
createNewBoard() {
|
createNewBoard() {
|
||||||
const self = this;
|
const self = this;
|
||||||
const promise = API.Board.create(this.form.board.value);
|
const promise = API.Board.create(this.form.name.value);
|
||||||
promise.then(
|
promise.then(
|
||||||
(data) => {
|
(data) => {
|
||||||
self.$emit('boardCreated', data);
|
self.$emit('boardCreated', data);
|
||||||
const board = getBoardFromResp(data);
|
const board = getBoardFromResp(data);
|
||||||
self.createdOptions.unshift(board);
|
self.createdOptions.unshift(board);
|
||||||
self.select(board);
|
self.select(board);
|
||||||
self.form.board.value = null;
|
self.form.name.value = null;
|
||||||
},
|
},
|
||||||
(resp) => {
|
(resp) => {
|
||||||
self.helper.markFieldsAsDanger(resp.data);
|
self.helper.markFieldsAsDanger(resp.data);
|
||||||
@@ -99,16 +99,17 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
'form.board.value': function (newVal) {
|
// eslint-disable-next-line func-names
|
||||||
|
'form.name.value': function (newVal) {
|
||||||
let availableOptions;
|
let availableOptions;
|
||||||
if (newVal === '' || newVal === null) {
|
if (newVal === '' || newVal === null) {
|
||||||
availableOptions = this.allOptions;
|
availableOptions = this.allOptions;
|
||||||
} else {
|
} else {
|
||||||
availableOptions = getFilteredOptions(
|
availableOptions = getFilteredOptions(
|
||||||
this.allOptions, this.form.board.value,
|
this.allOptions, this.form.name.value,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
this.availableOptions = availableOptions;
|
this.availableOptions = this.createdOptions.concat(availableOptions);
|
||||||
},
|
},
|
||||||
createdOptions() {
|
createdOptions() {
|
||||||
this.availableOptions = this.createdOptions.concat(this.availableOptions);
|
this.availableOptions = this.createdOptions.concat(this.availableOptions);
|
||||||
@@ -116,6 +117,10 @@ export default {
|
|||||||
allOptions() {
|
allOptions() {
|
||||||
this.availableOptions = this.allOptions;
|
this.availableOptions = this.allOptions;
|
||||||
},
|
},
|
||||||
|
selectedOptions() {
|
||||||
|
this.helper.resetAllFields();
|
||||||
|
this.$emit('selected', this.selectedOptions);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -59,7 +59,10 @@
|
|||||||
</b-field>
|
</b-field>
|
||||||
</div>
|
</div>
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<FilterSelect :allOptions="boardOptions"></FilterSelect>
|
<FilterSelect
|
||||||
|
:allOptions="boardOptions"
|
||||||
|
v-on:selected="onSelectBoard"
|
||||||
|
></FilterSelect>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
@@ -104,6 +107,7 @@ export default {
|
|||||||
formUpload: {
|
formUpload: {
|
||||||
imageId: null,
|
imageId: null,
|
||||||
},
|
},
|
||||||
|
boardId: null,
|
||||||
boardOptions: [],
|
boardOptions: [],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -128,6 +132,10 @@ export default {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
onSelectBoard(boardIds) {
|
||||||
|
console.log('boardId', boardIds);
|
||||||
|
this.boardIds = boardIds;
|
||||||
|
},
|
||||||
onUploadProcessing() {
|
onUploadProcessing() {
|
||||||
this.disableUrlField = true;
|
this.disableUrlField = true;
|
||||||
},
|
},
|
||||||
@@ -162,6 +170,14 @@ export default {
|
|||||||
bus.bus.$emit(bus.events.refreshPin);
|
bus.bus.$emit(bus.events.refreshPin);
|
||||||
self.$emit('pinCreated', resp);
|
self.$emit('pinCreated', resp);
|
||||||
self.$parent.close();
|
self.$parent.close();
|
||||||
|
if (self.boardIds !== null) {
|
||||||
|
// FIXME(winkidney): Should handle error for add-to board
|
||||||
|
self.boardIds.forEach(
|
||||||
|
(boardId) => {
|
||||||
|
API.Board.addToBoard(boardId, [resp.data.id]);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user