Commit 245114f0 authored by Jerome Chauveau's avatar Jerome Chauveau
Browse files

replace file feature fix + improve upload

parent 8fe4c4a8
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -448,8 +448,8 @@ export default {

    async replaceResourceSelected(){
      this.isReplacing = true;
      let path = this.currentCollection.title +"/" + this.currentCollection.ancestors.map(x => x.title).join('/')
      let r = await this.$store.dispatch('manageFilesUpload',
      let path = this.currentCollection.title +"/" + this.currentCollection.ancestors.map(x => x.title).join('/');
      let r = await this.$store.dispatch('filesUpload',
          {
            files : this.$refs['replaceInput'].files,
            path : path,
@@ -459,8 +459,8 @@ export default {
      if(r.message && r.message === 'already_uploaded'){
        replaceId = r.resourceId;
      }
      if(r[0] && r[0].status === 'available' && r[0].id) {
        replaceId = r[0].id
      if(r[0] && r[0].ok && r[0].resourceId) {
        replaceId = Number(r[0].resourceId)
      }
      if(replaceId){
        await this.$store.dispatch('replaceResource', {
@@ -468,7 +468,7 @@ export default {
          to : this.resource.id
        });
        this.$alertInfo("Ressource remplacée");
        EventBus.$emit('goto-resource', this.currentCollection.id, replaceId);
        EventBus.$emit('goto-resource', this.currentCollection.id, this.resource.id);
      }
      else {
        console.error(r);
+16 −7
Original line number Diff line number Diff line
@@ -471,32 +471,39 @@ export default new Vuex.Store({
            return response;
        },

        /**
         *
         * @param context
         * @param files
         * @param path
         * @param projectId
         */
       /* async filesUpload(context, {files, path, projectId}) {
            console.debug('files upload');
            return JamaRPClient.uploadFiles(files, projectId, path, context.getters.acceptedFormats);
        },*/

        /**
         *
         * @param context
         * @param files
         * @param path
         * @param projectId
         * @returns {boolean}
         */
        async manageFilesUpload(context, {files, path, projectId}) {
            let uploadResults = await JamaRPClient.uploadFiles(files, projectId, path, context.getters.acceptedFormats);
            let uploadResults = await JamaRPClient.uploadFiles(files, projectId, path, context.getters.acceptedFormats);//await this.filesUpload(context, {files, path, projectId})
            if(!uploadResults[0])
                return false;
            //let errorMessages = [];
            for (let i = 0; i < uploadResults.length; i++) {
                if (uploadResults[i].already_uploaded) {
                    try {
                        await JamaRPClient.addResourceToCollection(uploadResults[i].id, context.getters.currentCollection.id);
                        JamaRPClient.addResourceToCollection(uploadResults[i].id, context.getters.currentCollection.id);
                    } catch (e) {
                        console.log(e);
                        console.log('cannot add ' + uploadResults[i].id)
                    }
                }/* else {
                    if (uploadResults[i].chunk_errors || uploadResults[i].status === 'bad_format') {
                        errorMessages.push(uploadResults[i].message);
                }
                }*/
            }
            let onError = uploadResults.filter((ur) => !ur.ok);
            if(onError.length > 0 )
@@ -518,6 +525,8 @@ export default new Vuex.Store({
            return true;
        },



        /**
         *
         * @param context