diff --git a/app/Http/Controllers/API/ConceptController.php b/app/Http/Controllers/API/ConceptController.php index dde0fb4..b53f170 100644 --- a/app/Http/Controllers/API/ConceptController.php +++ b/app/Http/Controllers/API/ConceptController.php @@ -8,6 +8,7 @@ use App\Models\Concept; use App\Models\Term; use Illuminate\Http\Request; +use Illuminate\Http\Response; use Illuminate\Support\Facades\DB; class ConceptController extends Controller @@ -130,9 +131,25 @@ public function show($id) * @param int $id * @return \Illuminate\Http\Response */ - public function update(Request $request, $id) + public function update(Request $request, int $id) { - // + $concept = Concept::findOrFail($id); + $attributes = $request->all(); + + // Sync concept categories + if (array_key_exists('conceptCategories', $attributes)) { + $category_ids = array_map(function ($category) { + return $category['id']; + }, $attributes['conceptCategories']); + + $concept->conceptCategories()->sync($category_ids); + + unset($attributes['conceptCategories']); + } + + $concept->update($attributes); + + return new Response($concept); } /** diff --git a/resources/js/api/ConceptService.js b/resources/js/api/ConceptService.js index 0203d2c..94beea5 100644 --- a/resources/js/api/ConceptService.js +++ b/resources/js/api/ConceptService.js @@ -39,6 +39,15 @@ export default { } }, + async updateConcept(conceptId, conceptData) { + try { + const { data } = await apiClient.patch(`/${conceptId}`, conceptData); + return [null, data]; + } catch (error) { + return [error]; + } + }, + async deleteConcept(conceptId) { try { const { data } = await apiClient.delete(`/${conceptId}`); diff --git a/resources/js/api/ConceptSourceService.js b/resources/js/api/ConceptSourceService.js index 648a12a..bf1ec2c 100644 --- a/resources/js/api/ConceptSourceService.js +++ b/resources/js/api/ConceptSourceService.js @@ -41,7 +41,7 @@ export default { async updateConceptSource(conceptSourceId, conceptSourceData) { try { - const { data } = await apiClient.post( + const { data } = await apiClient.patch( `/${conceptSourceId}`, conceptSourceData, ); diff --git a/resources/js/app.js b/resources/js/app.js index 55ce275..b1bd412 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -35,7 +35,7 @@ import 'bootstrap-vue/dist/bootstrap-vue.css'; Vue.component('concept', require('./components/Concept.vue').default); Vue.component('concept-list', require('./components/Concept/List.vue').default); Vue.component('concept', require('./components/Concept/Default.vue').default); -Vue.component('concept-edit', require('./components/Concept/Edit.vue').default); +Vue.component('concept-edit', require('./components/Concept/LegacyEdit.vue').default); Vue.component( 'concept-category', require('./components/ConceptCategory.vue').default, @@ -44,23 +44,11 @@ Vue.component( 'concept-create', require('./components/Concept/Create.vue').default, ); -Vue.component( - 'concept-source', - require('./components/Source/Default.vue').default, -); -Vue.component( - 'concept-source-edit', - require('./components/Source/Edit.vue').default, -); Vue.component( 'concept-search', require('./components/ConceptSearch.vue').default, ); Vue.component('term-list', require('./components/Term/List.vue').default); -Vue.component( - 'category-list', - require('./components/Category/List.vue').default, -); Vue.component('term-item', require('./components/TermItem.vue').default); Vue.component('cpf-form', require('./components/CPFForm.vue').default); Vue.component('b-table', BTable); diff --git a/resources/js/components/CPFForm.vue b/resources/js/components/CPFForm.vue index 081d4ef..c2be593 100644 --- a/resources/js/components/CPFForm.vue +++ b/resources/js/components/CPFForm.vue @@ -626,7 +626,7 @@ + diff --git a/resources/js/components/Category/List.vue b/resources/js/components/Category/List.vue deleted file mode 100644 index 9683993..0000000 --- a/resources/js/components/Category/List.vue +++ /dev/null @@ -1,80 +0,0 @@ - - - - diff --git a/resources/js/components/Concept.vue b/resources/js/components/Concept.vue index aa12a60..3ed0367 100644 --- a/resources/js/components/Concept.vue +++ b/resources/js/components/Concept.vue @@ -12,7 +12,7 @@ - diff --git a/resources/js/components/Concept/Edit.vue b/resources/js/components/Concept/LegacyEdit.vue similarity index 98% rename from resources/js/components/Concept/Edit.vue rename to resources/js/components/Concept/LegacyEdit.vue index 883eae6..964b066 100644 --- a/resources/js/components/Concept/Edit.vue +++ b/resources/js/components/Concept/LegacyEdit.vue @@ -239,7 +239,7 @@ - - diff --git a/resources/js/components/Source/Edit.vue b/resources/js/components/Source/Edit.vue deleted file mode 100644 index f8bf3b2..0000000 --- a/resources/js/components/Source/Edit.vue +++ /dev/null @@ -1,173 +0,0 @@ - - - - - diff --git a/resources/js/components/Source/Editable.vue b/resources/js/components/Source/Editable.vue new file mode 100644 index 0000000..aea327d --- /dev/null +++ b/resources/js/components/Source/Editable.vue @@ -0,0 +1,312 @@ + + + + diff --git a/resources/js/components/Term/Editable.vue b/resources/js/components/Term/Editable.vue index 166c60b..9e0cc1a 100644 --- a/resources/js/components/Term/Editable.vue +++ b/resources/js/components/Term/Editable.vue @@ -1,37 +1,90 @@ diff --git a/resources/js/components/Term/List.vue b/resources/js/components/Term/List.vue index 070aa53..e6c8fe3 100644 --- a/resources/js/components/Term/List.vue +++ b/resources/js/components/Term/List.vue @@ -1,24 +1,41 @@ diff --git a/resources/js/components/Term/mixins/ConfirmDelete.js b/resources/js/components/Term/mixins/ConfirmDelete.js new file mode 100644 index 0000000..b9c53a2 --- /dev/null +++ b/resources/js/components/Term/mixins/ConfirmDelete.js @@ -0,0 +1,17 @@ +export default { + methods: { + showDeleteModal() { + this.$refs.deleteModal.show(); + }, + hideDeleteModal() { + this.$refs.deleteModal.hide(); + }, + confirmDelete() { + this.$emit('delete-term', this.termId, this.termIndex); + this.hideDeleteModal(); + }, + focusConfirmDeleteButton() { + this.$refs.confirmDeleteButton.focus(); + }, + }, +}; diff --git a/resources/js/components/Term/mixins/ConfirmPreferred.js b/resources/js/components/Term/mixins/ConfirmPreferred.js new file mode 100644 index 0000000..8a5bf2e --- /dev/null +++ b/resources/js/components/Term/mixins/ConfirmPreferred.js @@ -0,0 +1,17 @@ +export default { + methods: { + showPreferredModal() { + this.$refs.preferredModal.show(); + }, + hidePreferredModal() { + this.$refs.preferredModal.hide(); + }, + confirmPreferred() { + this.$emit('make-term-preferred', this.term, this.termIndex); + this.hidePreferredModal(); + }, + focusConfirmPreferredButton() { + this.$refs.confirmPreferredButton.focus(); + }, + }, +}; diff --git a/resources/js/components/Term/mixins/InlineEdit.js b/resources/js/components/Term/mixins/InlineEdit.js new file mode 100644 index 0000000..17234b9 --- /dev/null +++ b/resources/js/components/Term/mixins/InlineEdit.js @@ -0,0 +1,45 @@ +import state from '../../../states/concept'; + +export default { + data() { + return { + state, + }; + }, + computed: { + inlineEdit() { + return this.inEdit; + }, + }, + methods: { + conceptEditMode: function () { + return this.state.editMode; + }, + showCancelModal() { + this.$refs.cancelModal.show(); + }, + hideCancelModal() { + this.$refs.cancelModal.hide(); + }, + confirmCancel() { + this.$emit('cancel-inline-edit', this.term, this.termIndex); + this.text = this.originalText; + this.resetTerm(); + this.hideCancelModal(); + }, + focusConfirmCancelButton() { + this.$refs.confirmCancelButton.focus(); + }, + cancelInlineEdit() { + if (!this.inlineEdit || this.conceptEditMode()) { + return; + } + if (this.isDirty()) { + this.showCancelModal(); + return; + } + + this.confirmCancel(); + }, + }, +}; diff --git a/resources/js/config/catgegories.js b/resources/js/config/categories.js similarity index 100% rename from resources/js/config/catgegories.js rename to resources/js/config/categories.js diff --git a/resources/views/concepts/show.blade.php b/resources/views/concepts/show.blade.php index 492782d..bf23163 100644 --- a/resources/views/concepts/show.blade.php +++ b/resources/views/concepts/show.blade.php @@ -31,6 +31,7 @@ id="concept" :concept-props="{{ $concept }}" :term-props="{{ $concept->terms }}" + :categories-props="{{ $concept->conceptCategories }}" :sources-props="{{ $concept->sources }}" can-edit-vocabulary="{{ json_encode($isVocabularyEditor) }}" > diff --git a/routes/api.php b/routes/api.php index 3c74c9d..a8b3ec3 100644 --- a/routes/api.php +++ b/routes/api.php @@ -24,9 +24,7 @@ Route::put('concepts/{id}/relate_concept', 'ConceptController@relateConcepts'); Route::put('concepts/{id}/deprecate', 'API\ConceptController@deprecate'); -Route::apiResource('concepts', 'API\ConceptController')->except([ - 'update', -]); +Route::apiResource('concepts', 'API\ConceptController'); Route::get('concepts_summary', function () { // Return only the preferred term