Skip to content

Commit

Permalink
#12 Finishing app builder migration support
Browse files Browse the repository at this point in the history
- Updates externalURL
- Can open application from select application screen
- Applications aren't hidden behind showAll flag
  • Loading branch information
rpeach-sag committed Jan 13, 2020
1 parent 307b9cc commit ec4a0ab
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 20 deletions.
5 changes: 4 additions & 1 deletion src/FileDataClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,12 @@ export class FileDataClient extends DataClient {
}
}

async createApplication(app: IApplication, blob?: Blob): Promise<string | number> {
async createApplication(app: IApplication & {applicationBuilder?: any}, blob?: Blob): Promise<string | number> {
app = _.cloneDeep(app);
app.id = this.getNextManagedObjectId();
if (app.applicationBuilder) {
app.externalUrl = app.externalUrl.split('UNKNOWN-APP-ID').join(app.id.toString());
}
const json = await this.exportJsonFormat;
if (blob != undefined) {
app.activeVersionId = this.getNextManagedObjectId();
Expand Down
9 changes: 7 additions & 2 deletions src/HttpDataClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,15 @@ export class HttpDataClient extends DataClient {
return this.getBinaryBlob(app.binary, onProgress);
}

async createApplication(app: IApplication, blob?: Blob): Promise<string | number> {
async createApplication(app: IApplication & {applicationBuilder?: any}, blob?: Blob): Promise<string | number> {
// Create the app
const newApp = (await this.client.application.create(app)).data;

// Update the external URL for applicationBuilder apps
if (app.applicationBuilder) {
newApp.externalUrl = newApp.externalUrl.split('UNKNOWN-APP-ID').join(newApp.id.toString());
}

// Create the binary
await this.updateApplication(newApp, blob);

Expand Down Expand Up @@ -200,7 +205,7 @@ export class HttpDataClient extends DataClient {
})).json()).id;
}

await this.client.application.update({id: app.id, activeVersionId: app.activeVersionId, applicationBuilder: app.applicationBuilder} as IApplication);
await this.client.application.update({id: app.id, activeVersionId: app.activeVersionId, externalUrl: app.externalUrl, applicationBuilder: app.applicationBuilder} as IApplication);

return app.id
}
Expand Down
2 changes: 1 addition & 1 deletion src/destination/credentials/credentials.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class CredentialsComponent {
newContextPath: 'migration-tool',
newAppKey: 'migration-tool-application-key',
application: migrationToolApp
});
}, new Map<string, string|number>());
await dataClient.createApplication(newApp, binaryBlob);
alrt.update('Done! Redirecting...', 'success');
await delay(1000);
Expand Down
21 changes: 12 additions & 9 deletions src/migrate/migrate.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,15 +433,18 @@ export class MigrateComponent {
_.set(result, path, _.get(appMigration.application, path));
});

// Update application builder dashboard ids
if (result.applicationBuilder && result.applicationBuilder.dashboards) {
result.applicationBuilder.dashboards.forEach(dashboard => {
if (oldIdsToNewIds.has(dashboard.id.toString())) {
dashboard.id = oldIdsToNewIds.get(dashboard.id.toString());
} else {
// TODO: add to warning
}
})
if (result.applicationBuilder) {
result.externalUrl = appMigration.application.externalUrl.split(appMigration.application.id.toString()).join('UNKNOWN-APP-ID');
// Update application builder dashboard ids
if (result.applicationBuilder.dashboards) {
result.applicationBuilder.dashboards.forEach(dashboard => {
if (oldIdsToNewIds.has(dashboard.id.toString())) {
dashboard.id = oldIdsToNewIds.get(dashboard.id.toString());
} else {
// TODO: add to warning
}
})
}
}

// Update the application with the user provided changes...
Expand Down
4 changes: 2 additions & 2 deletions src/migrate/selectapplication/select-application.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class SelectApplicationComponent implements OnDestroy{

private dataClient: DataClient;
showAll$: BehaviorSubject<boolean> = new BehaviorSubject(false);
allApplications: Promise<(IApplication & {id: string|number, binary: IManagedObject})[]>;
allApplications: Promise<(IApplication & {id: string|number, binary: IManagedObject} & {applicationBuilder?: any})[]>;
filteredApplications: Promise<(IApplication & {id: string|number, binary: IManagedObject, downloading?:boolean})[]>;

showAllSubscription: Subscription;
Expand All @@ -49,7 +49,7 @@ export class SelectApplicationComponent implements OnDestroy{
this.dataClient = this.dataService.getSourceDataClient();
this.allApplications = this.dataClient.getApplicationsWithBinaries();
this.showAllSubscription = this.showAll$.subscribe(showAll => {
this.filteredApplications = this.allApplications.then(apps => sortById(apps.filter(app => showAll || app.binary)));
this.filteredApplications = this.allApplications.then(apps => sortById(apps.filter(app => showAll || app.binary || app.applicationBuilder)));
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/source/application/application.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<td>{{application.binary?.id}}</td>
<td>{{application.binary?.length | fileSize}}</td>
<td>
<button class="btn btn-default" *ngIf="application.contextPath" (click)="openApplication($event, application)" translate>Open</button>
<button class="btn btn-default" *ngIf="application.contextPath || application.externalUrl" (click)="openApplication($event, application)" translate>Open</button>
</td>
<td>
<button class="btn btn-default" *ngIf="application.binary" (click)="downloadApplication($event, application, application.binary)" translate>Download</button>
Expand Down
12 changes: 8 additions & 4 deletions src/source/application/application.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {DataClient} from "../../DataClient";
export class ApplicationComponent implements OnDestroy {
private dataClient: DataClient;
showAll$: BehaviorSubject<boolean> = new BehaviorSubject(false);
allApplications: Promise<(IApplication & {id: string|number, binary: IManagedObject})[]>;
allApplications: Promise<(IApplication & {id: string|number, binary: IManagedObject} & {applicationBuilder?: any})[]>;
filteredApplications: Promise<(IApplication & {id: string|number, binary: IManagedObject, downloading?:boolean})[]>;

showAllSubscription: Subscription;
Expand All @@ -45,7 +45,7 @@ export class ApplicationComponent implements OnDestroy {
this.dataClient = this.dataService.getSourceDataClient();
this.allApplications = this.dataClient.getApplicationsWithBinaries();
this.showAllSubscription = this.showAll$.subscribe(showAll => {
this.filteredApplications = this.allApplications.then(apps => sortById(apps.filter(app => showAll || app.binary)));
this.filteredApplications = this.allApplications.then(apps => sortById(apps.filter(app => showAll || app.binary || app.applicationBuilder)));
});
}

Expand Down Expand Up @@ -123,8 +123,12 @@ export class ApplicationComponent implements OnDestroy {

openApplication(event: MouseEvent, app: IApplication) {
event.stopPropagation();
const baseUrl = this.dataClient.getBaseUrl();
window.open(`${baseUrl}/apps/${app.contextPath}`, '_blank');
if (app.externalUrl) {
window.open(app.externalUrl, '_blank');
} else {
const baseUrl = this.dataClient.getBaseUrl();
window.open(`${baseUrl}/apps/${app.contextPath}`, '_blank');
}
}


Expand Down

0 comments on commit ec4a0ab

Please sign in to comment.