Commit a258f3bf authored by Jerome Chauveau's avatar Jerome Chauveau
Browse files

Suite des actions en lot (déplacement).

parent 458cd16c
Loading
Loading
Loading
Loading
Loading
+107 −109
Original line number Diff line number Diff line
@@ -31,7 +31,9 @@
              :key="index"
              @click="action.callback(selectedCollections, selectedResources)"
          >
            <v-list-item-icon><v-icon>{{action.icon}}</v-icon></v-list-item-icon>
            <v-list-item-icon>
              <v-icon>{{ action.icon }}</v-icon>
            </v-list-item-icon>
            <v-list-item-title>
              {{ action.title }}
            </v-list-item-title>
@@ -87,6 +89,7 @@
import {mapActions, mapGetters} from "vuex";
import CollectionTreeSelect from "./widgets/CollectionTreeSelect";
import EventBus from "../events/event-bus";

export default {
  name: "JamaActionsToolbar",
  components: {CollectionTreeSelect},
@@ -123,6 +126,8 @@ export default {

    currentCollection() {
      this.allSelected = false;
      this.excludedCollectionIds = [];
      this.excludedResourceIds = [];
    },

    selectedCollections(after, before) {
@@ -163,13 +168,13 @@ export default {
    resourcesSelectionLength() {
      return this.batchMode
          ? this.currentStats.resources_count - this.excludedResourceIds.length
          : this.selectedResources.length
          : this.selectedResources.length;
    },

    collectionsSelectionLength() {
      return this.batchMode
          ? this.currentStats.children_count - this.excludedCollectionIds.length
          : this.selectedCollections.length
          : this.selectedCollections.length;
    },

    isTreeWithRoot() {
@@ -207,8 +212,7 @@ export default {
        collections.map(r => r.selected = this.allSelected);
        this.$store.commit('setSelectedResources', resources);
        this.$store.commit('setSelectedCollections', collections);
        }
        else{
      } else {
        this.$store.commit('setSelectedResources', []);
        this.$store.commit('setSelectedCollections', []);
      }
@@ -219,14 +223,35 @@ export default {
      this.moveDestId = dest;
    },

    /**
     * build filtered ids selection for batch operations
     * */
    _buildFilterSelection(){
      let selection = {}
      if (this.batchMode) {
        selection.exclude = {
          resources_ids : this.excludedResourceIds,
          collections_ids : this.excludedCollectionIds
        }
      }
      else{
        let includedResourcesIds = this.selectedResources.map((r)=>r.id);
        let includedCollectionIds = this.selectedCollections.map((c)=>c.id);
        selection.include = {
          resources_ids : includedResourcesIds,
          collections_ids: includedCollectionIds
        }
      }
      return selection;
    },

    deleteSelection() {
      this.$jamaConfirm(this.$t('delete_confirm'), (res) => {
        if (res) {
          if(this.batchMode) {
          let selection = this._buildFilterSelection();
          this.$store.dispatch('removeSelection', {
            collectionId: this.currentCollection.id,
              excludedResources: this.excludedResourceIds,
              excludedCollections: this.excludedCollectionIds
            selection : selection
          }).then(() => {
            EventBus.$emit('reload-current-collection');
            this.$store.dispatch('fetchCollectionTree', this.currentCollection.id);
@@ -235,32 +260,7 @@ export default {
            this.excludedCollectionIds = [];
            this.batchMode = false;
          })
          }
          else {
            this.excludedResourceIds = [];
            this.excludedCollectionIds = [];
            this.selectedCollections.forEach((c) => {
              this.$store.dispatch('deleteCollection', {collectionId : c.id, recursive : true});
              this.$store.commit('setSelectedCollections', []);
              this.$store.dispatch('fetchCollectionTree', this.currentCollection.id);
            });
            this.selectedResources.forEach((r) => {
              this.$store.dispatch('removeResourceFromCollection',
                  {
                    resourceId: r.id,
                    collectionId: this.currentCollection.id
                  })
                  .then((res) => {
                    if(res){
                      this.$jamaClient.ancestorsFromResource(r.id).then((ancestors) => {//delete resource if no more ancestor
                        if(ancestors.length === 0) {
                          this.$store.dispatch('deleteResource', r.id);
                        }
                      })
                    }
                  })
            });
          }

        }
      })
    },
@@ -273,26 +273,24 @@ export default {
    moveSelection() {
      this.$jamaConfirm(this.$t('move_confirm'), (res) => {
        if (res) {
          let collectionsIds = []
          let resourcesIds = [];
          this.selectedCollections.map((c) => {
              collectionsIds.push(c.id)
          });
          this.selectedResources.map((r) => {
              resourcesIds.push(r.id)
          });
          this.$jamaClient.moveItems(
              this.currentCollection ? this.currentCollection.id : null,
              this.moveDestId,
              collectionsIds,
              resourcesIds).then(() => {
          let selection = this._buildFilterSelection();
          this.$store.dispatch('moveSelection', {
            fromCollectionId: this.currentCollection.id,
            toCollectionId: this.moveDestId,
            selection : selection
          }).then(() => {
            EventBus.$emit('reload-current-collection');
            this.$store.dispatch('fetchCollectionTree', this.currentCollection.id);
            this.$store.dispatch('fetchCollectionTree', this.moveDestId);
            this.$store.commit('setSelectedResources', []);
            this.excludedResourceIds = [];
            this.excludedCollectionIds = [];
            this.batchMode = false;
            this.$refs.treeViewSelect.selection = [];
            this.$emit('items-moved');//need to fetch &reload current collection
          });

        }});
            this.moveDialog = false;

          })
        }
      })
    },

    sortOptionsClicked(type) {
+5 −6
Original line number Diff line number Diff line
@@ -378,13 +378,12 @@ export default new Vuex.Store({
            return res;
        },

        async removeSelection(context, {collectionId, excludedResources= [], excludedCollections= []}){
            let selection = (excludedResources.length + excludedCollections.length) > 0
                ? {exclude : {resources_ids: excludedResources, collections_ids: excludedCollections}}:
                null;
        async removeSelection(context, {collectionId, selection}){
            return JamaRPClient.removeSelection(collectionId, selection);
        },

            let res = await JamaRPClient.removeSelection(collectionId, selection);
            return res;
        async moveSelection(context, {fromCollectionId, toCollectionId, selection}){
            return JamaRPClient.moveSelection(fromCollectionId, selection, toCollectionId);
        },

        async renameCollection(context, {collectionId, name}) {
+33 −1
Original line number Diff line number Diff line
@@ -1216,6 +1216,33 @@ class JamaClient {
        return this._rpc("move_items", [from_collection_id, to_collection_id, collections_ids, resources_ids]);
    }

    /**
     * Will mass move items based on parent collection and destination collection
     *
     * Use such an object for inclusion/exclusion:
     *
     * ```
     * {
     *     "include": {
     *         "resources_ids": [3493, 159]
     *         "collections_ids:" [20, 31]
     *     },
     *     "exclude": {
     *         "resources_ids": [12, 10, 15]
     *         "collections_ids:" [4, 254, 17]
     *     }
     * }
     * ```
     *
     * @param {BigInteger} from_collection_id
     * @param {Object} selection
     * @param {BigInteger} to_collection_id
     * @returns {Object}
     */
    async moveSelection(from_collection_id, selection, to_collection_id) {
        return this._rpc("move_selection", [from_collection_id, selection, to_collection_id]);
    }

    /**
     * Rotate and crop an image. The resulting image then replaces the
     * original in the current resource.
@@ -1339,13 +1366,18 @@ class JamaClient {
        return this._rpc("recycle_bin", [project_id]);
    }


    /**
     * Will mass remove items based on parent collection
     *
     * Use such an object for exclusion:
     * Use such an object for inclusion/exclusion:
     *
     * ```
     * {
     *     "include": {
     *         "resources_ids": [3493, 159]
     *         "collections_ids:" [20, 31]
     *     },
     *     "exclude": {
     *         "resources_ids": [12, 10, 15]
     *         "collections_ids:" [4, 254, 17]