summaryrefslogtreecommitdiffstats
path: root/catalog-ui/app/scripts/directives/file-upload/file-upload.ts
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2017-02-19 10:28:42 +0200
committerMichael Lando <ml636r@att.com>2017-02-19 10:51:01 +0200
commit451a3400b76511393c62a444f588a4ed15f4a549 (patch)
treee4f5873a863d1d3e55618eab48b83262f874719d /catalog-ui/app/scripts/directives/file-upload/file-upload.ts
parent5abfe4e1fb5fae4bbd5fbc340519f52075aff3ff (diff)
Initial OpenECOMP SDC commit
Change-Id: I0924d5a6ae9cdc161ae17c68d3689a30d10f407b Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'catalog-ui/app/scripts/directives/file-upload/file-upload.ts')
-rw-r--r--catalog-ui/app/scripts/directives/file-upload/file-upload.ts134
1 files changed, 134 insertions, 0 deletions
diff --git a/catalog-ui/app/scripts/directives/file-upload/file-upload.ts b/catalog-ui/app/scripts/directives/file-upload/file-upload.ts
new file mode 100644
index 0000000000..16db3e7e21
--- /dev/null
+++ b/catalog-ui/app/scripts/directives/file-upload/file-upload.ts
@@ -0,0 +1,134 @@
+/*-
+ * ============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=========================================================
+ */
+/**
+ * Created by obarda on 1/27/2016.
+ */
+/// <reference path="../../references"/>
+module Sdc.Directives {
+ 'use strict';
+
+ export class FileUploadModel {
+ filetype: string;
+ filename: string;
+ filesize: number;
+ base64: string;
+ }
+
+ export interface IFileUploadScope extends ng.IScope {
+ fileModel: FileUploadModel;
+ formElement:ng.IFormController;
+ extensions: string;
+ elementDisabled: string;
+ elementName: string;
+ elementRequired: string;
+ myFileModel: any; // From the ng bind to <input type=file
+ defaultText: string;
+ onFileChangedInDirective:Function;
+
+ getExtensionsWithDot():string;
+ onFileChange():void
+ onFileClick(element:any):void;
+ setEmptyError(element):void;
+ validateField(field:any):boolean;
+ cancel():void;
+ }
+
+
+ export class FileUploadDirective implements ng.IDirective {
+
+ constructor(private $templateCache:ng.ITemplateCacheService, private sdcConfig:Models.IAppConfigurtaion) {
+ }
+
+ scope = {
+ fileModel: '=',
+ formElement: '=',
+ extensions: '@',
+ elementDisabled: '@',
+ elementName: '@',
+ elementRequired: '@',
+ onFileChangedInDirective: '=?',
+ defaultText: '=',
+ };
+
+ restrict = 'E';
+ replace = true;
+ template = ():string => {
+ return this.$templateCache.get('/app/scripts/directives/file-upload/file-upload.html');
+ };
+
+ link = (scope:IFileUploadScope, element:any, $attr:any) => {
+
+ // In case the browse has filename, set it valid.
+ // When editing artifact the file is not sent again, so if we have filename I do not want to show error.
+ if (scope.fileModel && scope.fileModel.filename && scope.fileModel.filename!==''){
+ scope.formElement[scope.elementName].$setValidity('required', true);
+ }
+
+ scope.getExtensionsWithDot = ():string => {
+ let ret = [];
+ if(scope.extensions) {
+ _.each(scope.extensions.split(','), function (item) {
+ ret.push("." + item.toString());
+ });
+ }
+ return ret.join(",");
+ };
+
+ scope.onFileChange = ():void => {
+ if (scope.onFileChangedInDirective) {
+ scope.onFileChangedInDirective();
+ }
+ if (scope.myFileModel) {
+ scope.fileModel = scope.myFileModel;
+ scope.formElement[scope.elementName].$setValidity('required', true);
+ }
+ };
+
+ scope.setEmptyError = (element):void => {
+ if(element.files[0].size){
+ scope.formElement[scope.elementName].$setValidity('emptyFile', true);
+ }else{
+ scope.formElement[scope.elementName].$setValidity('emptyFile', false);
+ scope.fileModel = undefined;
+ }
+
+ };
+
+ // Workaround, in case user select a file then cancel (X) then select the file again, the event onChange is not fired.
+ // This is a workaround to fix this issue.
+ scope.onFileClick = (element:any):void => {
+ element.value = null;
+ };
+
+ scope.cancel = ():void => {
+ scope.fileModel.filename = '';
+ scope.formElement[scope.elementName].$pristine;
+ scope.formElement[scope.elementName].$setValidity('required', false);
+ }
+ };
+
+ public static factory = ($templateCache:ng.ITemplateCacheService, sdcConfig:Models.IAppConfigurtaion)=> {
+ return new FileUploadDirective($templateCache, sdcConfig);
+ };
+
+ }
+
+ FileUploadDirective.factory.$inject = ['$templateCache', 'sdcConfig'];
+}
//maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.openecomp.sdc</groupId> <artifactId>sdc-onboarding</artifactId> <packaging>pom</packaging> <parent> <groupId>org.openecomp.sdc</groupId> <artifactId>sdc-main</artifactId> <version>1.2.0-SNAPSHOT</version> </parent> <modules> <module>../common</module> <module>../openecomp-be</module> <module>../openecomp-ui</module> </modules> <properties> <!-- Maven plugin versions --> <jacoco.version>0.7.9</jacoco.version> <mvn.assembly.version>2.1</mvn.assembly.version> <mvn.compiler.version>2.5.1</mvn.compiler.version> <mvn.deploy.version>2.4</mvn.deploy.version> <mvn.hub.version>1.4.0</mvn.hub.version> <mvn.install.version>2.3.1</mvn.install.version> <mvn.jar.version>2.4</mvn.jar.version> <mvn.jaxb2.version>0.13.2</mvn.jaxb2.version> <mvn.license.version>1.10</mvn.license.version> <mvn.shade.version>2.3</mvn.shade.version> <mvn.surefire.version>2.19.1</mvn.surefire.version> <mvn.swagger.version>3.1.0</mvn.swagger.version> <mvn.war.version>2.1.1</mvn.war.version> <mvn.antrun.version>1.8</mvn.antrun.version> <!-- Onboarding artifacts version --> <openecomp.sdc.common.version>${project.version}</openecomp.sdc.common.version> <!-- Onboarding 3rd party versions --> <jtosca.version>1.1.1-SNAPSHOT</jtosca.version> <aspectj.version>1.8.9</aspectj.version> <bsh.version>2.0b5</bsh.version> <cassandra.version>2.1.9</cassandra.version> <cglib.nodep.version>3.2.4</cglib.nodep.version> <!--old : 2.1_3. new 3.2.4 --> <classmate.version>1.3.3</classmate.version> <commons.beanutils.version>1.9.3</commons.beanutils.version> <commons.codec.version>1.10</commons.codec.version> <!-- orignal 1.6 updated to resolve blackduck violation --> <commons.collections.version>4.1</commons.collections.version> <commons.digester.version>2.1</commons.digester.version> <commons.io.version>2.5</commons.io.version> <commons.lang.version>2.6</commons.lang.version> <!-- orignal 2.5. updated to resolve blackduck violation --> <commons.lang3.version>3.4</commons.lang3.version> <cxf.version>3.1.8</cxf.version> <datasatx.version>2.1.9</datasatx.version> <easymock.version>3.4</easymock.version> <groovy.version>2.4.7</groovy.version> <gson.version>2.3.1</gson.version> <fop.version>2.2</fop.version> <freemarker.version>2.3.26-incubating</freemarker.version> <hibernate.validator.version>5.3.3.Final</hibernate.validator.version> <!--5.3.1.Final changed to 5.3.3.Final to include jboss-logging 3.3.0.Final for 1702 --> <http.client.version>4.4.1</http.client.version> <httpasyncclient.version>4.1.2</httpasyncclient.version> <janino.version>2.7.7</janino.version> <jaxb.impl.version>2.2.11</jaxb.impl.version> <java.source>1.8</java.source> <java.target>1.8</java.target> <javax.el.version>2.2.4</javax.el.version> <javax.el-api.version>3.0.1-b04</javax.el-api.version> <!-- orignal 2.2.4 updated to resolve blackduck violation --> <javax.inject.version>1</javax.inject.version> <javax.servlet.version>2.5</javax.servlet.version> <jackson.version>2.8.1</jackson.version> <jackson.annotations.version>2.7.4</jackson.annotations.version> <jackson.dataformat.version>2.7.4</jackson.dataformat.version> <jackson.mapper.version>1.9.13</jackson.mapper.version> <jcommander.version>1.58</jcommander.version> <jetty.servlets.version>9.0.6.v20130930</jetty.servlets.version> <jersey.core.version>1.19.1</jersey.core.version> <jersey.multipart.version>1.18.1</jersey.multipart.version> <junit.version>RELEASE</junit.version> <logback.version>1.1.2</logback.version> <mockito.all.version>1.10.19</mockito.all.version> <org.codehaus.jackson.version>1.9.13</org.codehaus.jackson.version> <!-- orignal 1.9.2 --> <org.everit.json.schema.version>1.3.0</org.everit.json.schema.version> <!--new 1.4.1 orignal 1.3.0 updated to resolve blackduck violation --> <org.reflections.version>0.9.10</org.reflections.version> <!-- orignal 0.9.9 updated to resolve blackduck violation --> <powermock.version>1.6.5</powermock.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <servlet.version>2.5</servlet.version> <slf4j.version>1.7.21</slf4j.version> <snakeyaml.version>1.17</snakeyaml.version> <spring.framework.version>4.1.3.RELEASE</spring.framework.version> <!-- orignal 4.0.7.RELEASE 4.1.3.RELEASE--> <swagger.version>1.5.3</swagger.version> <testng.version>6.9.10</testng.version> <!--new 6.9.13.6 still shows blackduck risk --> <woodstox.version>4.4.1</woodstox.version> <ws.rs.version>2.0.1</ws.rs.version> <!-- New version 2.0.1 to fix blackduck violation Failing with comiplation issues--> <zusammen.version>0.2.0</zusammen.version> <zusammen-state-store.version>0.2.1</zusammen-state-store.version> <skipSA>true</skipSA> <pmd.version>5.8.1</pmd.version> <build.tools.version>${project.version}</build.tools.version> </properties> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jxr-plugin</artifactId> <version>2.5</version> <configuration> <skip>${skipSA}</skip> </configuration> <executions> <execution> <id>jxr-generation</id> <phase>verify</phase> <goals> <goal>jxr</goal> <goal>test-jxr</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <version>3.8</version> <configuration> <skip>${skipSA}</skip> <aggregate>false</aggregate> <targetJdk>${maven.compiler.target}</targetJdk> <rulesets> <ruleset>build-pmd-ruleset.xml</ruleset> </rulesets> </configuration> <executions> <execution> <id>pmd-check</id> <phase>verify</phase> <goals> <!-- violations fail build --> <goal>check</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>org.openecomp.sdc</groupId> <artifactId>build-tools</artifactId> <version>${build.tools.version}</version> </dependency> <dependency> <groupId>net.sourceforge.pmd</groupId> <artifactId>pmd-core</artifactId> <version>${pmd.version}</version> </dependency> <dependency> <groupId>net.sourceforge.pmd</groupId> <artifactId>pmd-java</artifactId> <version>${pmd.version}</version> </dependency> </dependencies> </plugin> </plugins> </build> </project>