123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- 'use strict';
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: Dashboard
- *| (C) Copyright IBM Corp. 2017
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['../../../lib/@waca/dashboard-common/dist/core/Collection', './SourceModel'], function (Collection, SourceModel) {
- 'use strict';
- /**
- * Wrapper model class around the moserJS module to allow us to extend the boardModel
- */
- var SourcesCollection = Collection.extend({
- // The class of objects that this collection manages
- modelClass: SourceModel,
- destroy: function destroy() {
- this.getModels().forEach(function (sourceModel) {
- sourceModel.destroy();
- });
- },
- /**
- * Adds a SourceModel to the collection
- * @param {string} sourceInfo.assetId the CM id of the source
- * @param {string} sourceInfo.name the name of the source
- * @param {string} sourceInfo.type the type of the source
- * @param {string} sourceInfo.searchPath the CM searchPath of the source
- * @param {object} options These options will be passed to the collection add method. Look at Collection.js for description.
- * allowDuplicateAssetIds option to enable adding multiple source with the same asset Id.
- * @return {string} The id of the source that was added
- */
- addSource: function addSource(sourceInfo, options) {
- var preventDuplicateAssetIdSources = !(options && options.allowDuplicateAssetIds);
- // If the source already exists don't do anything
- var existingSource = this._getExistingSource(sourceInfo.assetId);
- if (existingSource && preventDuplicateAssetIdSources) {
- return existingSource.id;
- }
- if (!sourceInfo.shaping) {
- sourceInfo.shaping = {}; // Need this since we want a default ShapingModel created
- }
- // Since we're adding a source we already have the localizedName - saves another CM call
- sourceInfo.localizedName = sourceInfo.name;
- sourceInfo.cmObjectExists = true;
- var newSourceModel = new SourceModel(sourceInfo);
- this.add(newSourceModel, options);
- return newSourceModel.id;
- },
- /**
- * Given an assetId (storeId) find the source in the collection
- * @param {String} assetId The storeId
- * @return {Object} The source Model or null if not found
- */
- _getExistingSource: function _getExistingSource(assetId) {
- var models = this.getModels();
- for (var i = 0; i < models.length; i++) {
- // Only match on sources that weren't added because of pinning
- if (assetId && models[i].get('assetId') === assetId && !models[i].get('pinSourceName')) {
- return models[i];
- }
- }
- return null;
- }
- });
- return SourcesCollection;
- });
- //# sourceMappingURL=SourcesCollection.js.map
|