2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
22 import {IAppMenu, Component, IAppConfigurtaion} from "app/models";
23 import {UrlToBase64Service} from "app/services";
25 export interface IPrintGraphScreenScope extends ng.IScope {
30 export class PrintGraphScreenDirective implements ng.IDirective {
32 constructor(private $filter:ng.IFilterService,
33 private sdcMenu:IAppMenu,
34 private sdcConfig:IAppConfigurtaion,
35 private urlToBase64Service:UrlToBase64Service) {
42 link = (scope:IPrintGraphScreenScope, element:any) => {
45 element.bind('click', function () {
50 let printScreen = ():void => {
52 // let pdf :any = new jsPDF('landscape', 'mm', 'a4');
53 // pdf.setProperties({
54 // title: scope.entity.name,
55 // subject: 'Design Snapshot for ' + scope.entity.name,
56 // author: scope.entity.creatorFullName,
57 // keywords: scope.entity.tags.join(', '),
58 // creator: scope.entity.creatorFullName
61 // // A4 measures is 210 × 297 millimeters
62 // let pdfWidth :number = 297,
63 // pdfHeight :number = 210,
64 // leftColumnWidth :number = 80;
66 // //left bar background
67 // pdf.setDrawColor(0);
68 // pdf.setFillColor(248, 249, 251);
69 // pdf.rect(0, 0, leftColumnWidth, pdfHeight, 'F');
72 // pdf.setFontSize(12);
73 // pdf.setTextColor(38, 61, 77);
74 // let splitTitle :any = pdf.splitTextToSize(scope.entity.name, 50);
75 // pdf.text(22, 15 - (splitTitle.length - 1) * 2, splitTitle);
78 // pdf.setLineWidth(0.2);
79 // pdf.setDrawColor(208, 209, 213);
80 // pdf.line(0, 28, leftColumnWidth, 28);
83 // pdf.setFontSize(10);
84 // let properties :any = getPdfProperties();
86 // let topOffset :number = 39, lines;
87 // properties.forEach( (item:any) => {
91 // if (item.title === 'Description:') {
95 // pdf.setTextColor(38, 61, 77);
96 // pdf.text(5, topOffset, item.title);
97 // pdf.setTextColor(102, 102, 102);
98 // lines = pdf.splitTextToSize(item.value, 49);
99 // pdf.text(5 + item.offset, topOffset, lines[0]);
100 // if (lines.length > 1) {
101 // lines = pdf.splitTextToSize(item.value.substring(lines[0].length + 1), 65);
102 // if (lines.length > 8) {
103 // lines = lines.slice(0, 7);
104 // lines[lines.length - 1] += '...';
106 // pdf.text(5, topOffset + 4, lines);
107 // topOffset += 4 * (lines.length);
114 // //another background in case the text was too long
115 // let declarationLineOffset :number = 176;
116 // pdf.setDrawColor(0);
117 // pdf.setFillColor(248, 249, 251);
118 // pdf.rect(0, declarationLineOffset, leftColumnWidth, pdfHeight - declarationLineOffset, 'F');
120 // pdf.setLineWidth(0.2);
121 // pdf.setDrawColor(208, 209, 213);
122 // pdf.line(0, declarationLineOffset, leftColumnWidth, declarationLineOffset);
125 // pdf.setFontSize(10.5);
126 // pdf.setTextColor(38, 61, 77);
127 // pdf.text(5, 185, 'Declaration');
128 // pdf.setFontSize(9);
129 // pdf.setTextColor(102, 102, 102);
130 // pdf.setFontType('bold');
131 // pdf.text(5, 190, this.$filter('translate')('PDF_FILE_DECLARATION_BOLD'));
132 // pdf.setFontType('normal');
133 // pdf.text(5, 194, pdf.splitTextToSize(this.$filter('translate')('PDF_FILE_DECLARATION'), 65));
137 // let addEntityIcon:Function = () => {
138 // let iconPath:string = self.sdcConfig.imagesPath + '/styles/images/';
139 // if (scope.entity.isService()) {
140 // iconPath += 'service-icons/' + scope.entity.icon + '.png';
142 // iconPath += 'resource-icons/' + scope.entity.icon + '.png';
144 // self.urlToBase64Service.downloadUrl(iconPath, (base64string:string):void => {
145 // if (base64string) {
146 // pdf.addImage(base64string, 'JPEG', 5, 7, 15, 15);
148 // pdf.save(scope.entity.name + '.pdf');
152 // //actual snapshop of canvas
153 // let diagramDiv :any = document.getElementById('myDiagram');
154 // let diagram :go.Diagram = go.Diagram.fromDiv(diagramDiv), canvasImg = new Image();
155 // diagram.startTransaction('print screen');
156 // let canvasImgBase64:any = diagram.makeImageData({
158 // size: new go.Size(pdfHeight * 5, NaN),
159 // background: 'white',
160 // type: 'image/jpeg'
162 // diagramDiv.firstElementChild.toDataURL();
163 // diagram.commitTransaction('print screen');
165 // canvasImg.onload = () => {
166 // if (canvasImg.height > 0) {
167 // let canvasImgRatio:number = Math.min((pdfWidth - leftColumnWidth - 15) / canvasImg.width, pdfHeight / canvasImg.height);
168 // let canvasImgWidth:number = canvasImg.width * canvasImgRatio,
169 // canvasImgHeight:number = canvasImg.height * canvasImgRatio;
170 // let canvasImgOffset:number = (pdfHeight - canvasImgHeight) / 2;
171 // pdf.addImage(canvasImg, 'JPEG', leftColumnWidth, canvasImgOffset, canvasImgWidth, canvasImgHeight);
177 // if(canvasImg.src === 'data:,') { //empty canvas
180 // canvasImg.src = canvasImgBase64;
185 let getPdfProperties = ():Array<any> => {
187 // {title: this.$filter('translate')('GENERAL_LABEL_TYPE'), value: scope.entity.getComponentSubType(), offset: 10},
188 // {title: this.$filter('translate')('GENERAL_LABEL_VERSION'), value: scope.entity.version, offset: 15},
189 // {title: this.$filter('translate')('GENERAL_LABEL_CATEGORY'), value: scope.entity.categories.length ? scope.entity.categories[0].name : '', offset: 16},
190 // {title: this.$filter('translate')('GENERAL_LABEL_CREATION_DATE'), value: this.$filter('date')(scope.entity.creationDate, 'MM/dd/yyyy'), offset: 24},
191 // {title: this.$filter('translate')('GENERAL_LABEL_AUTHOR'), value: scope.entity.creatorFullName, offset: 13},
192 // {title: this.$filter('translate')('GENERAL_LABEL_CONTACT_ID'), value: scope.entity.contactId, offset: 41},
193 // {title: this.$filter('translate')('GENERAL_LABEL_STATUS'), value: (<any>this.sdcMenu).LifeCycleStatuses[scope.entity.lifecycleState].text, offset: 13},
194 // {title: this.$filter('translate')('GENERAL_LABEL_DESCRIPTION'), value: scope.entity.description, offset: 20},
195 // {title: this.$filter('translate')('GENERAL_LABEL_TAGS'), value: scope.entity.tags.join(', '), offset: 10}
203 public static factory = ($filter:ng.IFilterService, sdcMenu:IAppMenu, sdcConfig:IAppConfigurtaion, urlToBase64Service:UrlToBase64Service)=> {
204 return new PrintGraphScreenDirective($filter, sdcMenu, sdcConfig, urlToBase64Service);
209 PrintGraphScreenDirective.factory.$inject = ['$filter', 'sdcMenu', 'sdcConfig', 'Sdc.Services.UrlToBase64Service'];