-
Notifications
You must be signed in to change notification settings - Fork 2
added import/export #655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
added import/export #655
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...p/components/admin-app/admin-app-template-export/admin-app-template-export.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| <!-- | ||
| Copyright 2021 Carnegie Mellon University. All Rights Reserved. | ||
| Released under a MIT (SEI)-style license. See LICENSE.md in the project root for license information. | ||
| --> | ||
|
|
||
| <h2>Export Application Templates</h2> | ||
|
|
||
| <form *ngIf="!(hasErrors$ | async)" [formGroup]="form" (ngSubmit)="export()"> | ||
| <mat-form-field *ngIf="isArchiveable"> | ||
| <mat-label>Archive Type</mat-label> | ||
| <mat-select formControlName="archiveType"> | ||
| <mat-option | ||
| *ngFor="let archiveType of archiveTypes" | ||
| [value]="archiveType" | ||
| > | ||
| {{ archiveType }} | ||
| </mat-option> | ||
| </mat-select> | ||
| </mat-form-field> | ||
|
|
||
| <div> | ||
| <mat-form-field floatLabel="always" appearance="none"> | ||
| <mat-label>Include Icons</mat-label> | ||
| <mat-slide-toggle | ||
| formControlName="includeIcons" | ||
| matTooltip="Include icon files in the exported archive" | ||
| ></mat-slide-toggle> | ||
| <textarea matInput hidden></textarea> | ||
| </mat-form-field> | ||
|
|
||
| <mat-form-field floatLabel="always" appearance="none"> | ||
| <mat-label>Embed Icons</mat-label> | ||
| <mat-slide-toggle | ||
| formControlName="embedIcons" | ||
| matTooltip="Embed included Icons into exported JSON as data URIs" | ||
| ></mat-slide-toggle> | ||
| <textarea matInput hidden></textarea> | ||
| </mat-form-field> | ||
| </div> | ||
|
|
||
| <div class="d-flex justify-content-around"> | ||
| <button | ||
| type="submit" | ||
| color="primary" | ||
| mat-raised-button | ||
| [disabled]="!form.valid || loading" | ||
| > | ||
| {{ | ||
| loading | ||
| ? 'Exporting....' | ||
| : 'Export ' + (ids.length == 0 ? 'All' : '(' + ids.length + ')') | ||
| }} | ||
| </button> | ||
|
|
||
| <button type="reset" color="primary" mat-raised-button (click)="cancel()"> | ||
| Cancel | ||
| </button> | ||
| </div> | ||
| </form> | ||
|
|
||
| <div *ngIf="hasErrors$ | async"> | ||
| <h3 class="text-danger"> | ||
| Some errors occurred during export. Check errors.txt in the archive for | ||
| details. | ||
| </h3> | ||
|
|
||
| <div class="d-flex justify-content-around"> | ||
| <button mat-raised-button color="primary" (click)="cancel()">OK</button> | ||
| </div> | ||
| </div> |
5 changes: 5 additions & 0 deletions
5
...p/components/admin-app/admin-app-template-export/admin-app-template-export.component.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| /* | ||
| Copyright 2021 Carnegie Mellon University. All Rights Reserved. | ||
| Released under a MIT (SEI)-style license. See LICENSE.md in the project root for license information. | ||
| */ | ||
|
|
26 changes: 26 additions & 0 deletions
26
...omponents/admin-app/admin-app-template-export/admin-app-template-export.component.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| Copyright 2021 Carnegie Mellon University. All Rights Reserved. | ||
| Released under a MIT (SEI)-style license. See LICENSE.md in the project root for license information. | ||
| */ | ||
|
|
||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
|
||
| import { AdminAppTemplateExportComponent } from './admin-app-template-export.component'; | ||
|
|
||
| describe('AdminAppTemplateExportComponent', () => { | ||
| let component: AdminAppTemplateExportComponent; | ||
| let fixture: ComponentFixture<AdminAppTemplateExportComponent>; | ||
|
|
||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({ | ||
| declarations: [AdminAppTemplateExportComponent] | ||
| }); | ||
| fixture = TestBed.createComponent(AdminAppTemplateExportComponent); | ||
| component = fixture.componentInstance; | ||
| fixture.detectChanges(); | ||
| }); | ||
|
|
||
| it('should create', () => { | ||
| expect(component).toBeTruthy(); | ||
| }); | ||
| }); |
115 changes: 115 additions & 0 deletions
115
...app/components/admin-app/admin-app-template-export/admin-app-template-export.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| // Copyright 2021 Carnegie Mellon University. All Rights Reserved. | ||
| // Released under a MIT (SEI)-style license. See LICENSE.md in the project root for license information. | ||
|
|
||
| import { | ||
| Component, | ||
| OnInit, | ||
| Input, | ||
| ChangeDetectionStrategy, | ||
| Output, | ||
| EventEmitter, | ||
| } from '@angular/core'; | ||
| import { | ||
| UntypedFormGroup, | ||
| UntypedFormBuilder, | ||
| Validators, | ||
| AbstractControl, | ||
| } from '@angular/forms'; | ||
| import { ApplicationService, ArchiveType } from '../../../generated/player-api'; | ||
| import FileDownloadUtils from '../../../utilities/file-download-utils'; | ||
| import HttpHeaderUtils from '../../../utilities/http-header-utils'; | ||
| import { BehaviorSubject, finalize, map } from 'rxjs'; | ||
|
|
||
| @Component({ | ||
| selector: 'app-admin-app-template-export', | ||
| templateUrl: './admin-app-template-export.component.html', | ||
| styleUrls: ['./admin-app-template-export.component.scss'], | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| }) | ||
| export class AdminAppTemplateExportComponent implements OnInit { | ||
| @Input() ids: string[]; | ||
|
|
||
| @Output() complete = new EventEmitter<boolean>(); | ||
|
|
||
| form: UntypedFormGroup; | ||
| isArchiveable: boolean = true; | ||
| archiveTypes = Object.keys(ArchiveType); | ||
| typeString: string; | ||
| includeIcons: AbstractControl; | ||
| loading = false; | ||
| hasErrors = new BehaviorSubject(false); | ||
| hasErrors$ = this.hasErrors.asObservable(); | ||
|
|
||
| constructor( | ||
| private applicationService: ApplicationService, | ||
| formBuilder: UntypedFormBuilder | ||
| ) { | ||
| this.form = formBuilder.group({ | ||
| archiveType: [this.archiveTypes[0]], | ||
| includeIcons: [false, Validators.required], | ||
| embedIcons: [{ value: false, disabled: true }, Validators.required], | ||
| }); | ||
|
|
||
| this.includeIcons = this.form.get('includeIcons'); | ||
| const embedIcons = this.form.get('embedIcons'); | ||
|
|
||
| this.includeIcons.valueChanges.subscribe((enabled: boolean) => { | ||
| if (enabled) { | ||
| embedIcons.enable(); | ||
| } else { | ||
| embedIcons.disable(); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| ngOnInit() {} | ||
|
sei-aschlackman marked this conversation as resolved.
Outdated
|
||
|
|
||
| export() { | ||
| this.onExport( | ||
| this.ids, | ||
| ArchiveType[this.form.value.archiveType], | ||
| this.form.value.includeIcons, | ||
| this.includeIcons.value ? this.form.value.embedIcons : false | ||
| ); | ||
| } | ||
|
|
||
| cancel() { | ||
| this.complete.emit(false); | ||
| } | ||
|
|
||
| private onExport( | ||
| ids: string[], | ||
| archiveType: ArchiveType, | ||
| includeIcons, | ||
| embedIcons | ||
| ) { | ||
| this.loading = true; | ||
| this.applicationService | ||
| .exportApplicationTemplates( | ||
| includeIcons, | ||
| embedIcons, | ||
| archiveType, | ||
| ids, | ||
| 'response' | ||
| ) | ||
| .pipe( | ||
| map((response) => { | ||
| return { | ||
| blob: response.body, | ||
| filename: HttpHeaderUtils.getFilename(response.headers), | ||
| hasErrors: HttpHeaderUtils.hasArchiveErrors(response.headers), | ||
| }; | ||
| }), | ||
| finalize(() => (this.loading = false)) | ||
| ) | ||
| .subscribe((result) => { | ||
| FileDownloadUtils.downloadFile(result.blob, result.filename); | ||
|
|
||
| if (result.hasErrors) { | ||
| this.hasErrors.next(true); | ||
| } else { | ||
| this.complete.emit(true); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
76 changes: 76 additions & 0 deletions
76
...p/components/admin-app/admin-app-template-import/admin-app-template-import.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| <!-- | ||
| Copyright 2021 Carnegie Mellon University. All Rights Reserved. | ||
| Released under a MIT (SEI)-style license. See LICENSE.md in the project root for license information. | ||
| --> | ||
|
|
||
| <h2>Import {{ typeString | titlecase }}</h2> | ||
|
|
||
| <form *ngIf="!(finished$ | async)" [formGroup]="form" (ngSubmit)="import()"> | ||
| <div class="d-flex flex-column gap-2"> | ||
| <div class="d-flex align-items-center gap-2"> | ||
| <button | ||
| type="button" | ||
| color="primary" | ||
| mat-raised-button | ||
| (click)="fileInput.click()" | ||
| > | ||
| Choose File | ||
| </button> | ||
| <input | ||
| hidden | ||
| (change)="onFileSelected($event)" | ||
| #fileInput | ||
| type="file" | ||
| accept=".zip, .tar.gz, .tgz" | ||
| /> | ||
| <span class="file-name">{{ this.form.value.archive?.name }}</span> | ||
| </div> | ||
|
|
||
| <mat-form-field floatLabel="always" appearance="none" fxLayout="row"> | ||
| <mat-label>Overwrite Existing</mat-label> | ||
| <mat-slide-toggle | ||
| formControlName="overwriteExisting" | ||
| matTooltip="If an Application Template with a matching Id already exists, overwrite it. Otherwise, report as a failure." | ||
| ></mat-slide-toggle> | ||
| <textarea matInput hidden></textarea> | ||
| </mat-form-field> | ||
| </div> | ||
|
|
||
| <div class="d-flex justify-content-around"> | ||
| <button | ||
| type="submit" | ||
| color="primary" | ||
| mat-raised-button | ||
| [disabled]="!form.valid || loading" | ||
| > | ||
| {{ loading ? 'Importing...' : 'Import' }} | ||
| </button> | ||
|
|
||
| <button type="reset" color="primary" mat-raised-button (click)="cancel()"> | ||
| Cancel | ||
| </button> | ||
| </div> | ||
| </form> | ||
|
|
||
| <div *ngIf="result$ | async as result"> | ||
| <ng-container *ngIf="result.failures.length > 0"> | ||
| <h3 class="text-danger"> | ||
| Error: The following Application Templates already exist and were not | ||
| updated: | ||
| </h3> | ||
|
|
||
| <ul> | ||
| <li *ngFor="let appTemplate of result.failures"> | ||
| {{ appTemplate }} | ||
| </li> | ||
| </ul> | ||
| </ng-container> | ||
|
|
||
| <ng-container *ngIf="result.failures.length == 0"> | ||
| <h3 class="text-success">Import Successful</h3> | ||
| </ng-container> | ||
|
|
||
| <div class="d-flex justify-content-around"> | ||
| <button mat-raised-button color="primary" (click)="cancel()">OK</button> | ||
| </div> | ||
| </div> |
5 changes: 5 additions & 0 deletions
5
...p/components/admin-app/admin-app-template-import/admin-app-template-import.component.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| /* | ||
| Copyright 2021 Carnegie Mellon University. All Rights Reserved. | ||
| Released under a MIT (SEI)-style license. See LICENSE.md in the project root for license information. | ||
| */ | ||
|
|
26 changes: 26 additions & 0 deletions
26
...omponents/admin-app/admin-app-template-import/admin-app-template-import.component.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| Copyright 2021 Carnegie Mellon University. All Rights Reserved. | ||
| Released under a MIT (SEI)-style license. See LICENSE.md in the project root for license information. | ||
| */ | ||
|
|
||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
|
||
| import { AdminAppTemplateImportComponent } from './admin-app-template-import.component'; | ||
|
|
||
| describe('AdminAppTemplateImportComponent', () => { | ||
| let component: AdminAppTemplateImportComponent; | ||
| let fixture: ComponentFixture<AdminAppTemplateImportComponent>; | ||
|
|
||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({ | ||
| declarations: [AdminAppTemplateImportComponent] | ||
| }); | ||
| fixture = TestBed.createComponent(AdminAppTemplateImportComponent); | ||
| component = fixture.componentInstance; | ||
| fixture.detectChanges(); | ||
| }); | ||
|
|
||
| it('should create', () => { | ||
| expect(component).toBeTruthy(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.