Skip to content

Commit de00a0a

Browse files
Merge branch 'master' of https://github.com/Azure/BatchLabs
2 parents 4d868a9 + fef812c commit de00a0a

25 files changed

+391
-40
lines changed

app/components/data/shared/cloud-file-picker/cloud-file-picker.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export class CloudFilePickerComponent implements ControlValueAccessor, OnInit, O
4040
private _subscriptions: Subscription[] = [];
4141

4242
constructor(private storageService: StorageService, private dialog: DialogService) {
43-
4443
this.fileGroupsData = this.storageService.containerListView(storageService.ncjFileGroupPrefix);
4544
this.fileGroupsData.items.subscribe((fileGroups) => {
4645
this.fileGroups = fileGroups;

app/components/data/shared/cloud-file-picker/cloud-file-picker.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
{{hint}}
55
</mat-hint>
66
</mat-form-field>
7-
<bl-button type="round" [action]="openFilePickerDialog"><i class="fa fa-file"></i></bl-button>
7+
<bl-button type="round" [action]="openFilePickerDialog" [disabled]="!containerId" title="Select file"><i class="fa fa-file"></i></bl-button>

app/components/data/shared/cloud-file-picker/cloud-file-picker.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
@import "app/styles/variables";
2+
3+
// todo: should probably share this CSS with file group sas
14
bl-cloud-file-picker {
25
display: flex;
36
align-items: center;
@@ -8,5 +11,16 @@ bl-cloud-file-picker {
811

912
bl-button {
1013
margin-left: 5px;
14+
15+
&.disabled[color] {
16+
cursor: not-allowed;
17+
background: map-get($primary, 50);
18+
color: $whitesmoke;
19+
20+
&:hover, &:focus, &:active {
21+
background: map-get($primary, 50);
22+
color: $whitesmoke;
23+
}
24+
}
1125
}
1226
}

app/components/data/shared/data.shared.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import { FileBrowseModule } from "app/components/file/browse";
55
import { CloudFilePickerComponent, CloudFilePickerDialogComponent } from "./cloud-file-picker";
66
import { StorageErrorDisplayComponent } from "./errors";
77
import { FileGroupPickerComponent } from "./file-group-picker";
8+
import { FileGroupSasComponent } from "./file-group-sas";
89
import { FileGroupsPickerComponent } from "./file-groups-picker";
910

1011
const components = [
11-
FileGroupPickerComponent, FileGroupsPickerComponent,
12+
FileGroupPickerComponent, FileGroupSasComponent, FileGroupsPickerComponent,
1213
CloudFilePickerComponent, CloudFilePickerDialogComponent,
1314
StorageErrorDisplayComponent,
1415
];
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import { Component, Input, OnChanges, OnDestroy, OnInit, forwardRef } from "@angular/core";
2+
import {
3+
ControlValueAccessor, FormControl, NG_VALIDATORS, NG_VALUE_ACCESSOR,
4+
} from "@angular/forms";
5+
import { autobind } from "core-decorators";
6+
import { List } from "immutable";
7+
import * as moment from "moment";
8+
import { Subscription } from "rxjs";
9+
10+
import { BlobContainer } from "app/models";
11+
import { ListContainerParams, StorageService } from "app/services";
12+
import { ListView } from "app/services/core";
13+
14+
import "./file-group-sas.scss";
15+
16+
// tslint:disable:no-forward-ref
17+
@Component({
18+
selector: "bl-file-group-sas",
19+
templateUrl: "file-group-sas.html",
20+
providers: [
21+
{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => FileGroupSasComponent), multi: true },
22+
{ provide: NG_VALIDATORS, useExisting: forwardRef(() => FileGroupSasComponent), multi: true },
23+
],
24+
})
25+
export class FileGroupSasComponent implements ControlValueAccessor, OnChanges, OnInit, OnDestroy {
26+
@Input() public label: string;
27+
@Input() public hint: string;
28+
29+
/**
30+
* Name of the file group from which to pick a file.
31+
*/
32+
@Input() public containerId: string;
33+
34+
public fileGroups: List<BlobContainer>;
35+
public value = new FormControl();
36+
public fileGroupsData: ListView<BlobContainer, ListContainerParams>;
37+
public warning = false;
38+
39+
private _propagateChange: (value: any[]) => void = null;
40+
private _subscriptions: Subscription[] = [];
41+
42+
constructor(private storageService: StorageService) {
43+
this.fileGroupsData = this.storageService.containerListView(storageService.ncjFileGroupPrefix);
44+
this.fileGroupsData.items.subscribe((fileGroups) => {
45+
this.fileGroups = fileGroups;
46+
});
47+
48+
this._subscriptions.push(this.value.valueChanges.debounceTime(400).distinctUntilChanged().subscribe((value) => {
49+
this._checkValid(value);
50+
if (this._propagateChange) {
51+
this._propagateChange(value);
52+
}
53+
}));
54+
}
55+
56+
public ngOnChanges(inputs) {
57+
if (this.containerId && inputs.containerId &&
58+
inputs.containerId.currentValue !== inputs.containerId.previousValue) {
59+
this.generateSasToken();
60+
} else {
61+
this.value.setValue(null);
62+
}
63+
}
64+
65+
public ngOnInit() {
66+
this.fileGroupsData.fetchNext();
67+
}
68+
69+
public ngOnDestroy() {
70+
this._subscriptions.forEach(x => x.unsubscribe());
71+
this.fileGroupsData.dispose();
72+
}
73+
74+
public writeValue(value: string) {
75+
this.value.setValue(value);
76+
}
77+
78+
public registerOnChange(fn) {
79+
this._propagateChange = fn;
80+
}
81+
82+
public registerOnTouched() {
83+
this.value.markAsTouched();
84+
}
85+
86+
public validate(c: FormControl) {
87+
return null;
88+
}
89+
90+
@autobind()
91+
public generateSasToken() {
92+
/**
93+
* Blob Container read access policy that is valid for 7 days, The maximum
94+
* lifetime of a task in Batch.
95+
*/
96+
const accessPolicy = {
97+
AccessPolicy: {
98+
Permissions: "rl",
99+
ResourceTypes: "CONTAINER",
100+
Services: "BLOB",
101+
Start: moment.utc().add(-15, "minutes").toDate(),
102+
Expiry: moment.utc().add(7, "day").toDate(),
103+
},
104+
};
105+
106+
this.storageService.generateSharedAccessContainerUrl(this.containerId, accessPolicy).subscribe((value) => {
107+
this.value.setValue(value);
108+
});
109+
}
110+
111+
private _checkValid(value: string) {
112+
const valid = !value || this.fileGroups.map(x => x.name).includes(value);
113+
this.warning = !valid;
114+
}
115+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<mat-form-field>
2+
<input type="text" matInput [formControl]="value" [placeholder]="label">
3+
<mat-hint *ngIf="hint" align="end">
4+
{{hint}}
5+
</mat-hint>
6+
</mat-form-field>
7+
<bl-button type="round" [action]="generateSasToken" [disabled]="!containerId" title="Generate SAS"><i class="fa fa-refresh"></i></bl-button>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@import "app/styles/variables";
2+
3+
// todo: should probably share this CSS with file group picker
4+
bl-file-group-sas {
5+
display: flex;
6+
align-items: center;
7+
8+
mat-form-field {
9+
flex: 1;
10+
}
11+
12+
bl-button {
13+
margin-left: 5px;
14+
15+
&.disabled[color] {
16+
cursor: not-allowed;
17+
background: map-get($primary, 50);
18+
color: $whitesmoke;
19+
20+
&:hover, &:focus, &:active {
21+
background: map-get($primary, 50);
22+
color: $whitesmoke;
23+
}
24+
}
25+
26+
.fa-refresh {
27+
color: $whitesmoke;
28+
}
29+
}
30+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./file-group-sas.component";

app/components/file/browse/node-file-browse.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
</bl-file-explorer>
33
<div *ngIf="!isNodeAvailable" class="info-overlay node-unavailable">
44
Node is currently
5-
<span class="highlight">{{node.state}}&nbsp;</span>there is no files to view now.
5+
<span class="highlight">'{{node?.state}}'&nbsp;</span>there is no files to view now.
66
</div>

app/components/market/submit/market-application.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export enum NcjParameterExtendedType {
77
int = "int",
88
fileGroup = "file-group",
99
fileInFileGroup = "file-in-file-group",
10+
fileGroupSas = "file-group-sas",
1011
dropDown = "drop-down",
1112
}
1213

0 commit comments

Comments
 (0)