Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit 8b8d878

Browse files
oodamienghillert
authored andcommitted
Stream deploy: add copy-to-clipboard
Resolves #663
1 parent 6dcb762 commit 8b8d878

File tree

6 files changed

+63
-10
lines changed

6 files changed

+63
-10
lines changed

ui/src/app/streams/stream-deploy/builder/builder.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,9 @@
353353
<button tabindex="200" id="btn-export" type="button" class="btn btn-default" (click)="exportProps()">
354354
Export
355355
</button>
356+
<button tabindex="200" id="btn-copy" type="button" class="btn btn-default" (click)="copyToClipboard()">
357+
Copy to Clipboard
358+
</button>
356359
<button tabindex="200" id="btn-deploy-builder" type="submit" class="btn btn-primary"
357360
[disabled]="!isSubmittable(builder)">
358361
Deploy the stream

ui/src/app/streams/stream-deploy/builder/builder.component.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ export class StreamDeployBuilderComponent implements OnInit, OnDestroy {
5050
*/
5151
@Output() deploy = new EventEmitter();
5252

53+
/**
54+
* Emit for request copy
55+
*/
56+
@Output() copyProperties = new EventEmitter();
57+
5358
/**
5459
* Properties to load
5560
*/
@@ -575,4 +580,11 @@ export class StreamDeployBuilderComponent implements OnInit, OnDestroy {
575580
this.exportProperties.emit(this.getProperties());
576581
}
577582

583+
/**
584+
* Copye to clipboard
585+
*/
586+
copyToClipboard() {
587+
this.copyProperties.emit(this.getProperties());
588+
}
589+
578590
}

ui/src/app/streams/stream-deploy/free-text/free-text.component.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</div>
99
</ng-template>
1010
</div>
11-
<textarea dataflowAutoResize autofocus formControlName="input"></textarea>
11+
<textarea dataflowAutoResize [dataflowFocus]="true" formControlName="input"></textarea>
1212
</div>
1313
<div class="input-file">
1414
<label class="btn-file btn btn-default" placement="top" delay="500"
@@ -20,9 +20,12 @@
2020
</div>
2121
<app-page-actions>
2222
<a id="btn-cancel" class="btn btn-default" routerLink="/streams">Cancel</a>
23-
<button id="btn-export" type="button" class="btn btn-default" [disabled]="!isExportable" (click)="exportProps()">
23+
<button id="btn-export" type="button" class="btn btn-default" (click)="exportProps()">
2424
Export
2525
</button>
26+
<button tabindex="200" id="btn-copy" type="button" class="btn btn-default" (click)="copyToClipboard()">
27+
Copy to Clipboard
28+
</button>
2629
<button id="btn-deploy" type="submit" class="btn btn-primary" [disabled]="!isSubmittable">
2730
Deploy the stream
2831
</button>

ui/src/app/streams/stream-deploy/free-text/free-text.component.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ export class StreamDeployFreeTextComponent implements OnInit, OnDestroy {
3131
*/
3232
@Output() exportProperties = new EventEmitter();
3333

34+
/**
35+
* Emit for request copy
36+
*/
37+
@Output() copyProperties = new EventEmitter();
38+
3439
/**
3540
* Emit for request deploy
3641
*/
@@ -156,6 +161,13 @@ export class StreamDeployFreeTextComponent implements OnInit, OnDestroy {
156161
this.exportProperties.emit(this.getCleanProperties());
157162
}
158163

164+
/**
165+
* Copye to clipboard
166+
*/
167+
copyToClipboard() {
168+
this.copyProperties.emit(this.getCleanProperties());
169+
}
170+
159171
/**
160172
* Emit a request deploy
161173
*/

ui/src/app/streams/stream-deploy/stream-deploy.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
<div *ngIf="state.view == 'builder'">
3838
<app-stream-deploy-builder [properties]="properties" [skipper]="config.skipper" [id]="config.id"
3939
(exportProperties)="runExport($event)" (update)="update($event)"
40-
(deploy)="runDeploy($event)">
40+
(deploy)="runDeploy($event)" (copyProperties)="runCopy($event)">
4141
</app-stream-deploy-builder>
4242
</div>
4343
<div *ngIf="state.view == 'freetext'">
4444
<app-stream-deploy-free-text [properties]="properties" (update)="update($event)" [id]="config.id"
4545
(exportProperties)="runExport($event)" (update)="update($event)"
46-
(deploy)="runDeploy($event)">
46+
(deploy)="runDeploy($event)" (copyProperties)="runCopy($event)">
4747
</app-stream-deploy-free-text>
4848
</div>
4949
</div>

ui/src/app/streams/stream-deploy/stream-deploy.component.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { NotificationService } from '../../shared/services/notification.service'
1616
import { LoggerService } from '../../shared/services/logger.service';
1717
import { HttpAppError, AppError } from '../../shared/model/error.model';
1818
import { EMPTY } from 'rxjs/index';
19+
import { ClipboardService } from 'ngx-clipboard';
1920

2021
/**
2122
* Component used to deploy stream definitions.
@@ -77,6 +78,7 @@ export class StreamDeployComponent implements OnInit, OnDestroy {
7778
* @param {LoggerService} loggerService
7879
* @param {StreamDeployService} streamDeployService
7980
* @param {Router} router
81+
* @param {ClipboardService} clipboardService
8082
* @param {SharedAboutService} sharedAboutService
8183
*/
8284
constructor(private route: ActivatedRoute,
@@ -86,6 +88,7 @@ export class StreamDeployComponent implements OnInit, OnDestroy {
8688
private loggerService: LoggerService,
8789
private streamDeployService: StreamDeployService,
8890
private router: Router,
91+
private clipboardService: ClipboardService,
8992
private sharedAboutService: SharedAboutService) {
9093
}
9194

@@ -192,11 +195,31 @@ export class StreamDeployComponent implements OnInit, OnDestroy {
192195
*/
193196
runExport(value: Array<string>) {
194197
this.update(value);
195-
const propertiesText = this.properties.join('\n');
196-
const date = moment().format('YYYY-MM-HHmmss');
197-
const filename = `${this.refConfig.id}_${date}.txt`;
198-
const blob = new Blob([propertiesText], { type: 'text/plain' });
199-
saveAs(blob, filename);
198+
if (this.properties.length === 0) {
199+
this.notificationService.error('There are no properties to export.');
200+
} else {
201+
const propertiesText = this.properties.join('\n');
202+
const date = moment().format('YYYY-MM-HHmmss');
203+
const filename = `${this.refConfig.id}_${date}.txt`;
204+
const blob = new Blob([propertiesText], { type: 'text/plain' });
205+
saveAs(blob, filename);
206+
}
207+
}
208+
209+
/**
210+
* Run copy to clipboard
211+
* Update the properties
212+
* @param value Array of properties
213+
*/
214+
runCopy(value: Array<string>) {
215+
this.update(value);
216+
if (this.properties.length === 0) {
217+
this.notificationService.error('There are no properties to copy.');
218+
} else {
219+
const propertiesText = this.properties.join('\n');
220+
this.clipboardService.copyFromContent(propertiesText);
221+
this.notificationService.success('The properties have been copied to your clipboard.');
222+
}
200223
}
201224

202225
/**
@@ -242,7 +265,7 @@ export class StreamDeployComponent implements OnInit, OnDestroy {
242265
const busy = obs.pipe(takeUntil(this.ngUnsubscribe$))
243266
.subscribe(data => {
244267
if (update) {
245-
this.notificationService.success(`Successfully update stream definition "${this.refConfig.id}"`);
268+
this.notificationService.success(`Successfully updated stream definition "${this.refConfig.id}"`);
246269
} else {
247270
this.notificationService.success(`Successfully deployed stream definition "${this.refConfig.id}"`);
248271
}

0 commit comments

Comments
 (0)