summaryrefslogtreecommitdiffstats
path: root/catalog-be/etc
diff options
context:
space:
mode:
authoraribeiro <anderson.ribeiro@est.tech>2020-09-01 13:29:56 +0100
committerSébastien Determe <sebastien.determe@intl.att.com>2020-09-07 13:57:24 +0000
commitcda67b6e9d477cad22de6d4ef5834e61c83db0a9 (patch)
tree6d7976fa363415ab5e74bfc6690eb3405b1fd9fd /catalog-be/etc
parent3e9a9769dd21f0b16b3f238e42349cba3b1a78de (diff)
Add and change node_filter unit testes
Issue-ID: SDC-3272 Signed-off-by: aribeiro <anderson.ribeiro@est.tech> Change-Id: I29ff07fa5e4d4cec1379018d417e35a156e7aa2f
Diffstat (limited to 'catalog-be/etc')
0 files changed, 0 insertions, 0 deletions
href='#n103'>103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */
/// <reference path="../../references"/>
module Sdc.Directives {
    'use strict';

    export class DOWNLOAD_CSS_CLASSES {
        static DOWNLOAD_ICON = "table-download-btn tosca";
        static LOADER_ICON = "tlv-loader small loader";
    }

    export interface IDownloadArtifactScope extends ng.IScope {
        $window:any;
        artifact: Models.ArtifactModel;
        component: Models.Components.Component;
        instance:boolean;
        download: Function;
        showLoader:boolean;
        updateDownloadIcon:Function;
    }

    export class DownloadArtifactDirective implements ng.IDirective {

        constructor(private $window:any,private cacheService:Services.CacheService, private EventListenerService:Services.EventListenerService, private fileUtils:Sdc.Utils.FileUtils) {}

        scope = {
            artifact: '=',
            component: '=',
            instance:'=',
            showLoader:'='
        };
        restrict = 'EA';

        link = (scope:IDownloadArtifactScope, element:any) => {
            scope.$window = this.$window;

            element.on("click", function() {
                scope.download(scope.artifact);
            });


            let initDownloadLoader = ()=>{
                //if the artifact is in a middle of download progress register form callBack & change icon from download to loader
                if(scope.showLoader &&  this.cacheService.get(scope.artifact.uniqueId)){
                    this.EventListenerService.registerObserverCallback(Utils.Constants.EVENTS.DOWNLOAD_ARTIFACT_FINISH_EVENT + scope.artifact.uniqueId, scope.updateDownloadIcon);
                    window.setTimeout(():void => {
                        if(this.cacheService.get(scope.artifact.uniqueId)){
                            element[0].className = DOWNLOAD_CSS_CLASSES.LOADER_ICON;
                        }
                    },1000);

                }
            };

            let setDownloadedFileLoader = ()=> {
                if(scope.showLoader){
                    //set in cache service thet the artifact is in download progress
                    this.cacheService.set(scope.artifact.uniqueId,true);
                    initDownloadLoader();
                }
            };

            let removeDownloadedFileLoader = ()=> {
                if (scope.showLoader) {
                    this.cacheService.set(scope.artifact.uniqueId, false);
                    this.EventListenerService.notifyObservers(Utils.Constants.EVENTS.DOWNLOAD_ARTIFACT_FINISH_EVENT + scope.artifact.uniqueId);
                }
            };


            //replace the loader to download icon
            scope.updateDownloadIcon = () =>{
                element[0].className =  DOWNLOAD_CSS_CLASSES.DOWNLOAD_ICON;
            };


            initDownloadLoader();

            scope.download = (artifact:Models.ArtifactModel):void => {

                let onFaild = (response):void => {
                    console.info('onFaild', response);
                    removeDownloadedFileLoader();
                };

                let onSuccess = (data:Models.IFileDownload):void => {
                    downloadFile(data);
                    removeDownloadedFileLoader();
                };

                setDownloadedFileLoader();

                if(scope.instance){
                    scope.component.downloadInstanceArtifact(artifact.uniqueId).then(onSuccess, onFaild);
                }else {
                    scope.component.downloadArtifact(artifact.uniqueId).then(onSuccess, onFaild);
                }
            };

            let downloadFile =  (file:Models.IFileDownload):void => {
              if (file){
                  let blob = this.fileUtils.base64toBlob(file.base64Contents,'');
                  let fileName = file.artifactName;
                  this.fileUtils.downloadFile(blob, fileName);
              }
            };

            element.on('$destroy', ()=>{
                //remove listener of download event
                if(scope.artifact && scope.artifact.uniqueId){
                    this.EventListenerService.unRegisterObserver(Utils.Constants.EVENTS.DOWNLOAD_ARTIFACT_FINISH_EVENT + scope.artifact.uniqueId);
                }
            });

        };

        public static factory = ($window:any,cacheService:Sdc.Services.CacheService,EventListenerService:Services.EventListenerService, fileUtils:Sdc.Utils.FileUtils)=> {
            return new DownloadArtifactDirective($window,cacheService,EventListenerService, fileUtils);
        };

    }

    DownloadArtifactDirective.factory.$inject = ['$window', 'Sdc.Services.CacheService', 'EventListenerService', 'FileUtils'];
}