Commit 3d2e9e6c authored by Jerome Chauveau's avatar Jerome Chauveau
Browse files

Suppression en lot.

parent c0a2bbd3
Loading
Loading
Loading
Loading
+68 −23
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@
<script>
import {mapActions, mapGetters} from "vuex";
import CollectionTreeSelect from "./widgets/CollectionTreeSelect";
import EventBus from "../events/event-bus";
export default {
  name: "JamaActionsToolbar",
  components: {CollectionTreeSelect},
@@ -98,8 +99,10 @@ export default {
  data(){
    return {
      moveDialog: false,
      //allSelected : false,
      moveDestId : null,
      batchMode: false, //!= allSelected. batchMode is only toggled by 'all' checkbox click
      excludedCollectionIds: [],
      excludedResourceIds: [],
      actions: [
        {
          title : this.$t('move'),
@@ -125,11 +128,20 @@ export default {
    selectedCollections(after, before){
      if(after.length < before.length)
        this.allSelected = false;
      let removed = before.filter(x => !after.includes(x)).map((e) => e.id);
      let added = after.filter(x => !before.includes(x)).map((e) => e.id);
      this.excludedCollectionIds = this.excludedCollectionIds.concat(removed);
      this.excludedCollectionIds = this.excludedCollectionIds.filter((c) => added.indexOf(c) < 0);

    },

    selectedResources(after, before){
      if(after.length < before.length)
        this.allSelected = false;
      let removed = before.filter(x => !after.includes(x)).map((e) => e.id);
      let added = after.filter(x => !before.includes(x)).map((e) => e.id);
      this.excludedResourceIds = this.excludedResourceIds.concat(removed);
      this.excludedResourceIds = this.excludedResourceIds.filter((c) => added.indexOf(c) < 0);
    }
  },

@@ -149,13 +161,15 @@ export default {
    },

    resourcesSelectionLength(){
      return this.selectedResources.length
      // return !this.selectedResources ? 0 : this.selectedResources.filter(r => r.selected).length;
      return this.batchMode
          ? this.currentStats.resources_count - this.excludedResourceIds.length
          : this.selectedResources.length
    },

    collectionsSelectionLength(){
      return this.selectedCollections.length
      // return !this.selectedCollections ? 0  : this.selectedCollections.filter(r => r.selected).length
      return this.batchMode
          ? this.currentStats.children_count - this.excludedCollectionIds.length
          : this.selectedCollections.length
    },

    isTreeWithRoot(){
@@ -172,7 +186,15 @@ export default {
      }
    },

    ...mapGetters(["sortOptions","collections","resources","currentCollection","currentProjectId","selectedResources","selectedCollections"])
    ...mapGetters([
      "sortOptions",
      "collections",
      "resources",
      "currentStats",
      "currentCollection",
      "currentProjectId",
      "selectedResources",
      "selectedCollections"])
  },

  methods: {
@@ -190,6 +212,7 @@ export default {
          this.$store.commit('setSelectedResources', []);
          this.$store.commit('setSelectedCollections', []);
        }
        this.batchMode = this.allSelected;
    },

    moveDestSelected(dest){
@@ -199,12 +222,34 @@ export default {
     deleteSelection(){
      this.$jamaConfirm(this.$t('delete_confirm'), (res) => {
        if(res){
          if(this.batchMode) {
            this.$store.dispatch('removeSelection', {
              collectionId: this.currentCollection.id,
              excludedResources: this.excludedResourceIds,
              excludedCollections: this.excludedCollectionIds
            }).then(() => {
              EventBus.$emit('reload-current-collection');
              this.$store.dispatch('fetchCollectionTree', this.currentCollection.id);
              this.$store.commit('setSelectedResources', []);
              this.excludedResourceIds = [];
              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.commit('setSelectedCollections', []);
              this.$store.dispatch('fetchCollectionTree', this.currentCollection.id);
            });
            this.selectedResources.forEach((r) => {
            this.$store.dispatch('removeResourceFromCollection',{resourceId: r.id, collectionId: this.currentCollection.id})
              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
@@ -214,9 +259,9 @@ export default {
                      })
                    }
                  })
            this.$store.commit('setSelectedResources', [])
            });
          }
        }
      })
    },

+1 −0
Original line number Diff line number Diff line
@@ -634,6 +634,7 @@ export default {
      });
      this.loading = false;
      this.reloadCurrentCollection();
      this.$store.dispatch('fetchCollectionTree', this.currentCollection.id);
    },

    reloadCurrentCollection() {
+9 −0
Original line number Diff line number Diff line
@@ -378,6 +378,15 @@ 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;

            let res = await JamaRPClient.removeSelection(collectionId, selection);
            return res;
        },

        async renameCollection(context, {collectionId, name}) {
            let r = await JamaRPClient.renameCollection(collectionId, name);

+26 −0
Original line number Diff line number Diff line
@@ -1339,6 +1339,32 @@ class JamaClient {
        return this._rpc("recycle_bin", [project_id]);
    }

    /**
     * Will mass remove items based on parent collection
     *
     * Use such an object for exclusion:
     *
     * ```
     * {
     *     "exclude": {
     *         "resources_ids": [12, 10, 15]
     *         "collections_ids:" [4, 254, 17]
     *     }
     * }
     * ```
     *
     * deleteCollection (with recursion) and deleteResource are used under the hood.
     *
     * The parent collection is left as-is.
     *
     * @param {BigInteger} parent_collection_id
     * @param {Object} selection
     * @returns {Boolean}
     */
    async removeSelection(parent_collection_id, selection) {
        return this._rpc("remove_selection", [parent_collection_id, selection]);
    }


    /**
     * Remove a meta value from a collection given their ids.