From 280daa7f3f858ecfef9c91ffd5dea1007f021048 Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Sun, 19 Mar 2017 11:29:37 +0000
Subject: [PATCH] #3527 fix - Added applications and some minor refactoring
---
securis/src/main/webapp/src/app/forms/license.form.component.ts | 91 ++++++++++++++++++++++++++++++++-------------
1 files changed, 65 insertions(+), 26 deletions(-)
diff --git a/securis/src/main/webapp/src/app/forms/license.form.component.ts b/securis/src/main/webapp/src/app/forms/license.form.component.ts
index ba627af..e2604f9 100644
--- a/securis/src/main/webapp/src/app/forms/license.form.component.ts
+++ b/securis/src/main/webapp/src/app/forms/license.form.component.ts
@@ -1,53 +1,92 @@
import { Http } from '@angular/http';
import { LicensesService } from '../resources/licenses';
+import { PacksService } from '../resources/packs';
import { LocaleService } from '../common/i18n';
import { TdDataTableService, TdDataTableSortingOrder, ITdDataTableSortChangeEvent, ITdDataTableColumn } from '@covalent/core';
import { IPageChangeEvent } from '@covalent/core';
-import { Component, AfterViewInit } from '@angular/core';
-import { TdMediaService } from '@covalent/core';
-import { IComboOption } from './base';
+import { AfterViewInit, Component, ViewChild } from '@angular/core';
+import { ActivatedRoute, Router } from '@angular/router';
+
+import { TdMediaService, TdFileInputComponent } from '@covalent/core';
+import { FormBase, IComboOption } from './base';
+import { ToastsManager } from "ng2-toastr/ng2-toastr";
+
+declare var window: any;
@Component({
selector: 'license-form',
templateUrl: 'src/app/forms/license.form.html'
})
-export class LicenseFormComponent implements AfterViewInit {
+export class LicenseFormComponent extends FormBase {
- form_title: string = 'Title';
+ @ViewChild('requestFileUploader') requestFileUploader : TdFileInputComponent;
+ form_title: string = '';
form_subtitle: string = '';
data: any = {};
+ pack: any = null;
isNew : boolean = true;
constructor(private http: Http,
- private packs: LicensesService,
- private $L: LocaleService) {
-
+ private licenses: LicensesService,
+ private router: Router,
+ private packs: PacksService,
+ toaster: ToastsManager,
+ route: ActivatedRoute,
+ $L: LocaleService) {
+ super($L, route, toaster, licenses, $L.get('license'));
}
- private loadCombos(): void {
- /*
- this.http.get('organization')
- .map(response => response.json().map((org : any) => <IComboOption>{id: org.id, label: `(${org.code}) ${org.name}`}))
- .subscribe(
- data => this.organizations = (<IComboOption[]>data).sort((e1, e2) => e1.label.localeCompare(e2.label)),
- err => console.error('Error loading orgs')
- );
- */
- }
-
- log(obj: any) {
- console.log(obj)
+ requestFileSelected(file: File) : void {
+ console.log(file);
+ console.log(this.requestFileUploader);
+ if (!window.FileReader) { // Browser is not
+ // compatible
+ console.log(this.$L.get("Open your .req file with a text editor and copy&paste the content in the form text field?"));
+ return;
+ }
+ var reader = new FileReader();
+ reader.onerror = (err) => console.error(err);
+
+ reader.onload = (event) => {
+ this.data.request_data = reader.result;
+ }
+ reader.readAsText(file);
+ this.requestFileUploader.clear();
+ }
+
+ requestFileUploaded(file: File) : void {
+ console.log(file);
}
- ngOnInit(): void {
- this.loadCombos();
- this.data = {};
- this.form_title = this.$L.get('License data');
- this.form_subtitle = this.$L.get(this.isNew ? 'Create a new license': 'Modify the license data') ;
+ createActivationCode() : string {
+ // http://www.ietf.org/rfc/rfc4122.txt
+ var s = new Array(36);
+ var hexDigits = "0123456789abcdef";
+ for (var i = 0; i < 36; i++) {
+ s[i] = hexDigits.substr(Math.random() * 0x10 | 0, 1);
+ }
+ s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
+ s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
+ s[8] = s[13] = s[18] = s[23] = "-";
+
+ var uuid = s.join("");
+ return uuid;
+ }
+
+ goBack(): void {
+ this.router.navigate([`packs/${this.pack.id}/licenses`]);
}
ngAfterViewInit(): void {
+
+ this.route.params.subscribe(params => {
+ var packId = +params['packId']; // (+) converts string 'id' to a number
+ super.prepareData('licenseId', {
+ pack_id: packId,
+ activation_code: this.createActivationCode()
+ });
+ });
}
}
--
Gitblit v1.3.2