Skip to content

Commit

Permalink
Fix use of vue-resource for Vue 3
Browse files Browse the repository at this point in the history
  • Loading branch information
mzur committed Feb 13, 2025
1 parent fe4a848 commit e15a62a
Show file tree
Hide file tree
Showing 29 changed files with 99 additions and 73 deletions.
4 changes: 3 additions & 1 deletion resources/assets/js/annotations/api/exportArea.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Resource} from 'vue-resource';

/**
* Resource for editing the export area of a volume
*
Expand All @@ -13,4 +15,4 @@
* resource.delete({id: columeId}).then(...);
*
*/
export default Vue.resource('/api/v1/volumes{/id}/export-area');
export default Resource('/api/v1/volumes{/id}/export-area');
7 changes: 4 additions & 3 deletions resources/assets/js/annotations/api/volumes.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {Resource} from 'vue-resource';

/**
* Resource for the area of images of a volume.
*
* var resource = biigle.$require('annotations.api.volumeImageArea');
*
* Get the area in m² of all images of the volume:
* resource.get({id: 1}).then(...);
*
* @type {Vue.resource}
*/
export default Vue.resource('api/v1/volumes{/id}/images/area');
export default Resource('api/v1/volumes{/id}/images/area');

19 changes: 16 additions & 3 deletions resources/assets/js/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
import Vue from 'vue';
import VueResource from 'vue-resource';
import { configureCompat } from 'vue'
import { Resource, Http } from 'vue-resource';

configureCompat({
FILTERS: false,
});

window.Vue = Vue;
window.Vue.use(VueResource);

// Vue resource is not officially supported with Vue 3 and it no longer works as Vue
// plugin. It can be used stand-alone, though, and this is what we do for now. Any
// change here would require significant work with the existing resource definitions.
Vue.resource = function () {
console.trace('Vue.resource is deprecated. Import Resource directly.');
return Resource(...arguments);
};

const httpRootElement = document.querySelector('meta[name="http-root"]');

if (httpRootElement) {
Http.options.root = httpRootElement.getAttribute('content');
}

const csrfTokenElement = document.querySelector('meta[name="csrf-token"]');

if (csrfTokenElement) {
const readMethods = ['HEAD', 'GET', 'OPTIONS'];

Vue.http.interceptors.push(function(request) {
Http.interceptors.push(function(request) {
// Only add the CSRF token for non-read requests. This is important for
// remote volume locations and CORS, as it would require a special CORS
// configuration to allow this header.
Expand Down
6 changes: 3 additions & 3 deletions resources/assets/js/core/api/annotations.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Resource} from 'vue-resource';

/**
* Resource for annotations.
*
Expand All @@ -15,10 +17,8 @@
* Detach a label from an annotation:
* resource.detachLabel({annotation_label_id: id}).then(...);
* Note that the annotation label ID is required for this and not the annotation ID!
*
* @type {Vue.resource}
*/
export default Vue.resource('api/v1/annotations{/id}', {}, {
export default Resource('api/v1/annotations{/id}', {}, {
attachLabel: {
method: 'POST',
url: 'api/v1/annotations{/id}/labels',
Expand Down
6 changes: 3 additions & 3 deletions resources/assets/js/core/api/images.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Resource} from 'vue-resource';

/**
* Resource for images.
*
Expand Down Expand Up @@ -25,10 +27,8 @@
*
* Delete an image:
* resource.delete({id: 1}).then(...);
*
* @type {Vue.resource}
*/
export default Vue.resource('api/v1/images{/id}', {}, {
export default Resource('api/v1/images{/id}', {}, {
getFile: {
method: 'GET',
url: 'api/v1/images{/id}/file',
Expand Down
6 changes: 3 additions & 3 deletions resources/assets/js/core/api/labelSource.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Resource} from 'vue-resource';

/**
* Resource for finding labels from an external source.
*
Expand All @@ -6,7 +8,5 @@
* Find labels:
*
* resource.query({id: 1, query: 'Kolga'}).then(...);
*
* @type {Vue.resource}
*/
export default Vue.resource('api/v1/label-sources{/id}/find');
export default Resource('api/v1/label-sources{/id}/find');
6 changes: 3 additions & 3 deletions resources/assets/js/core/api/labelTree.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Resource} from 'vue-resource';

/**
* Resource for label trees.
*
Expand Down Expand Up @@ -29,10 +31,8 @@
*
* Detach a user from a label tree:
* resource.delete({id: 1, user_id: 1}).then(...);
*
* @type {Vue.resource}
*/
export default Vue.resource('api/v1/label-trees{/id}', {}, {
export default Resource('api/v1/label-trees{/id}', {}, {
addAuthorizedProject: {
method: 'POST',
url: 'api/v1/label-trees{/id}/authorized-projects',
Expand Down
6 changes: 3 additions & 3 deletions resources/assets/js/core/api/labelTreeVersion.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Resource} from 'vue-resource';

/**
* Resource for label tree versions.
*
Expand All @@ -8,10 +10,8 @@
* Delete a label tree version:
* resource.delete({id: 1}).then(...);
*
* @type {Vue.resource}
*/
export default Vue.resource('api/v1/label-tree-versions{/id}', {}, {
export default Resource('api/v1/label-tree-versions{/id}', {}, {
save: {
method: 'POST',
url: 'api/v1/label-trees{/id}/version',
Expand Down
6 changes: 3 additions & 3 deletions resources/assets/js/core/api/labels.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Resource} from 'vue-resource';

/**
* Resource for labels.
*
Expand All @@ -20,10 +22,8 @@
* Delete a label:
*
* resource.delete({id: labelId}).then(...);
*
* @type {Vue.resource}
*/
export default Vue.resource('api/v1/labels{/id}', {}, {
export default Resource('api/v1/labels{/id}', {}, {
save: {
method: 'POST',
url: 'api/v1/label-trees{/label_tree_id}/labels',
Expand Down
6 changes: 3 additions & 3 deletions resources/assets/js/core/api/notifications.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Resource} from 'vue-resource';

/**
* Resource for DB notifications.
*
Expand All @@ -10,10 +12,8 @@
* Delete:
*
* resource.delete({id: notificationId}).then(...)
*
* @type {Vue.resource}
*/
export default Vue.resource('api/v1/notifications{/id}', {}, {
export default Resource('api/v1/notifications{/id}', {}, {
markRead: {method: 'PUT'},
markReadAll: {
method: 'PUT',
Expand Down
6 changes: 3 additions & 3 deletions resources/assets/js/core/api/projects.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Resource} from 'vue-resource';

/**
* Resource for projects.
*
Expand Down Expand Up @@ -52,10 +54,8 @@
*
* Detach a label tree from a project:
* resource.detachLabelTree({id: 1, label_tree_id: 31}).then(...);
*
* @type {Vue.resource}
*/
export default Vue.resource('api/v1/projects{/id}', {}, {
export default Resource('api/v1/projects{/id}', {}, {
queryVolumes: {
method: 'GET',
url: 'api/v1/projects{/id}/volumes',
Expand Down
6 changes: 3 additions & 3 deletions resources/assets/js/core/api/users.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Resource} from 'vue-resource';

/**
* Resource for users.
*
Expand Down Expand Up @@ -29,10 +31,8 @@
*
* Query users by name:
* resource.find({query: 'jo'}).then(...);
*
* @type {Vue.resource}
*/
export default Vue.resource('api/v1/users{/id}', {}, {
export default Resource('api/v1/users{/id}', {}, {
find: {
method: 'GET',
url: 'api/v1/users/find{/query}',
Expand Down
6 changes: 3 additions & 3 deletions resources/assets/js/core/api/volumes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Resource} from 'vue-resource';

/**
* Resource for volumes.
*
Expand All @@ -11,7 +13,5 @@
*
* Update a volume:
* resource.update({id: 1}, {name: 'New Name'}).then(...);
*
* @type {Vue.resource}
*/
export default Vue.resource('api/v1/volumes{/id}');
export default Resource('api/v1/volumes{/id}');
6 changes: 3 additions & 3 deletions resources/assets/js/label-trees/api/mergeLabelTrees.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {Resource} from 'vue-resource';

/**
* Resource for merging of label trees.
*
* var resource = biigle.$require('api.annotations');
*
* Merge label trees:
* resource.save({id: 1}, {add: [...], remove: [...]}).then(...);
*
* @type {Vue.resource}
*/
export default Vue.resource('api/v1/label-trees{/id}/merge-labels');
export default Resource('api/v1/label-trees{/id}/merge-labels');
4 changes: 3 additions & 1 deletion resources/assets/js/projects/api/attachableVolumes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Resource} from 'vue-resource';

/**
* Resource for volume that can be attached to a project.
*
Expand All @@ -8,4 +10,4 @@
* var resource = biigle.$require('api.attachableVolumes');
* resource.get({id: projectId}).then(...);
*/
export default Vue.resource('api/v1/projects{/id}/attachable-volumes{/name}');
export default Resource('api/v1/projects{/id}/attachable-volumes{/name}');
4 changes: 3 additions & 1 deletion resources/assets/js/projects/api/projectInvitations.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Resource} from 'vue-resource';

/**
* Resource for project invitations.
*
Expand All @@ -7,7 +9,7 @@
* Delete an invitations.
* resource.delete({id: invitationId}).then(...);
*/
export default Vue.resource('api/v1/projects{/id}/invitations', {}, {
export default Resource('api/v1/projects{/id}/invitations', {}, {
delete: {
method: 'DELETE',
url: 'api/v1/project-invitations{/id}',
Expand Down
4 changes: 3 additions & 1 deletion resources/assets/js/projects/api/volumeStatistics.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Resource} from 'vue-resource';

/**
* Resource for volume statistics.
*
Expand All @@ -8,4 +10,4 @@
* var resource = biigle.$require('api.volumeStatistics');
* resource.get({id: volumeId}).then(...);
*/
export default Vue.resource('api/v1/volumes{/id}/statistics');
export default Resource('api/v1/volumes{/id}/statistics');
4 changes: 3 additions & 1 deletion resources/assets/js/reports/api/projectReports.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Resource} from 'vue-resource';

/**
* Resource for requesting reports for projects
*
Expand All @@ -12,4 +14,4 @@
* }).then(...)
*
*/
export default Vue.resource('/api/v1/projects{/id}/reports');
export default Resource('/api/v1/projects{/id}/reports');
4 changes: 3 additions & 1 deletion resources/assets/js/reports/api/volumeReports.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Resource} from 'vue-resource';

/**
* Resource for requesting reports for volumes
*
Expand All @@ -13,4 +15,4 @@
* }).then(...)
*
*/
export default Vue.resource('/api/v1/volumes{/id}/reports');
export default Resource('/api/v1/volumes{/id}/reports');
6 changes: 3 additions & 3 deletions resources/assets/js/sync/api/import.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Resource} from 'vue-resource';

/**
* Resource for imports.
*
Expand All @@ -8,7 +10,5 @@
*
* Delete an import:
* resource.delete({token: '123abc'}).then(...);
*
* @type {Vue.resource}
*/
export default Vue.resource('api/v1/import{/token}');
export default Resource('api/v1/import{/token}');
6 changes: 3 additions & 3 deletions resources/assets/js/videos/api/videoAnnotations.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Resource} from 'vue-resource';

/**
* Resource for video annotations.
*
Expand Down Expand Up @@ -29,10 +31,8 @@
*
* Detach a label:
* resource.detachLabel({id: annotationLabelId}).then(...);
*
* @type {Vue.resource}
*/
export default Vue.resource('api/v1/video-annotations{/id}', {}, {
export default Resource('api/v1/video-annotations{/id}', {}, {
query: {
method: 'GET',
url: 'api/v1/videos{/id}/annotations',
Expand Down
6 changes: 3 additions & 3 deletions resources/assets/js/videos/api/videos.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Resource} from 'vue-resource';

/**
* Resource for videos.
*
Expand All @@ -11,10 +13,8 @@
*
* Delete a video:
* resource.delete({id: videoId}, {force: false}).then(...);
*
* @type {Vue.resource}
*/
export default Vue.resource('api/v1/videos{/id}', {}, {
export default Resource('api/v1/videos{/id}', {}, {
save: {
method: 'POST',
url: 'api/v1/projects{/id}/videos',
Expand Down
6 changes: 3 additions & 3 deletions resources/assets/js/volumes/api/annotationSessions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Resource} from 'vue-resource';

/**
* Resource for annotation sessions.
*
Expand All @@ -21,10 +23,8 @@
*
* Delete a session:
* resource.delete({id: 2}).then(...);
*
* @type {Vue.resource}
*/
export default Vue.resource('api/v1/annotation-sessions{/id}', {}, {
export default Resource('api/v1/annotation-sessions{/id}', {}, {
query: {
method: 'GET',
url: 'api/v1/volumes{/volume_id}/annotation-sessions',
Expand Down
Loading

0 comments on commit e15a62a

Please sign in to comment.