Skip to content

Commit 42c4ee0

Browse files
committed
Moving console initialization in subclass
1 parent 2130be5 commit 42c4ee0

File tree

3 files changed

+44
-34
lines changed

3 files changed

+44
-34
lines changed

client/src/app/site/console/bash/bash.component.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ export class BashComponent extends AbstractConsoleComponent {
2121
this.consoleType = ConsoleTypes.BASH;
2222
}
2323

24+
protected initializeConsole() {
25+
this.siteSubscription = this.consoleService.getSite().subscribe(site => {
26+
this.site = site;
27+
});
28+
this.publishingCredSubscription = this.consoleService.getPublishingCredentials().subscribe(publishingCredentials => {
29+
this.publishingCredentials = publishingCredentials;
30+
});
31+
}
32+
2433
/**
2534
* Get the tab-key command for bash console
2635
*/

client/src/app/site/console/shared/components/abstract.console.component.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OnInit, OnDestroy, ComponentFactoryResolver, ComponentFactory, ComponentRef, ViewChild, ViewContainerRef, ElementRef, Input, EventEmitter } from '@angular/core';
1+
import { OnInit, OnDestroy, ComponentFactoryResolver, ComponentFactory, ComponentRef, ViewChild, ViewContainerRef, ElementRef, Input} from '@angular/core';
22
import { ArmObj } from '../../../../shared/models/arm/arm-obj';
33
import { Site } from '../../../../shared/models/arm/site';
44
import { PublishingCredentials } from '../../../../shared/models/publishing-credentials';
@@ -19,9 +19,7 @@ export abstract class AbstractConsoleComponent implements OnInit, OnDestroy {
1919
public initialized = false;
2020
protected enterPressed = false;
2121
protected site: ArmObj<Site>;
22-
protected siteInitialized = new EventEmitter();
2322
protected publishingCredentials: ArmObj<PublishingCredentials>;
24-
protected publishingCredentialsInitialized = new EventEmitter();
2523

2624
/*** Variables for Tab-key ***/
2725
protected listOfDir: string[] = [];
@@ -39,8 +37,8 @@ export abstract class AbstractConsoleComponent implements OnInit, OnDestroy {
3937
private _msgComponents: ComponentRef<any>[] = [];
4038
private _currentPrompt: ComponentRef<any> = null;
4139
private _resourceIdSubscription: Subscription;
42-
private _siteSubscription: Subscription;
43-
private _publishingCredSubscription: Subscription;
40+
protected siteSubscription: Subscription;
41+
protected publishingCredSubscription: Subscription;
4442

4543
@Input()
4644
public appName: string;
@@ -60,27 +58,25 @@ export abstract class AbstractConsoleComponent implements OnInit, OnDestroy {
6058
ngOnInit() {
6159
this._resourceIdSubscription = this._consoleService.getResourceId().subscribe(resourceId => {
6260
this.resourceId = resourceId; });
63-
this._siteSubscription = this._consoleService.getSite().subscribe(site => {
64-
this.site = site;
65-
this.siteInitialized.emit(null);
66-
});
67-
this._publishingCredSubscription = this._consoleService.getPublishingCredentials().subscribe(publishingCredentials => {
68-
this.publishingCredentials = publishingCredentials;
69-
this.publishingCredentialsInitialized.emit(null);
70-
});
61+
this.initializeConsole();
7162
this.initialized = true;
7263
this.focusConsole();
7364
}
7465

7566
ngOnDestroy() {
7667
this._resourceIdSubscription.unsubscribe();
77-
this._siteSubscription.unsubscribe();
78-
this._publishingCredSubscription.unsubscribe();
68+
this.siteSubscription.unsubscribe();
69+
this.publishingCredSubscription.unsubscribe();
7970
if (this.lastAPICall && !this.lastAPICall.closed) {
8071
this.lastAPICall.unsubscribe();
8172
}
8273
}
8374

75+
/**
76+
*
77+
*/
78+
protected abstract initializeConsole();
79+
8480
/**
8581
* Mouse Press outside the console,
8682
* i.e. the console no longer in focus

client/src/app/site/console/shared/components/abstract.windows.component.ts

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { AbstractConsoleComponent } from './abstract.console.component';
22
import { ComponentFactoryResolver } from '@angular/core';
33
import { ConsoleService } from '../services/console.service';
44
import { Regex, ConsoleConstants, HttpMethods } from '../../../../shared/models/constants';
5-
import { Observable } from 'rxjs/Observable';
65

76
export abstract class AbstractWindowsComponent extends AbstractConsoleComponent {
87
private _defaultDirectory = 'D:\\home\\site\\wwwroot';
@@ -14,28 +13,34 @@ export abstract class AbstractWindowsComponent extends AbstractConsoleComponent
1413
) {
1514
super(componentFactoryResolver, consoleService);
1615
this.dir = this._defaultDirectory;
17-
Observable.zip(this.siteInitialized, this.publishingCredentialsInitialized)
18-
.subscribe(r => {
19-
this.updateDefaultDirectory();
20-
});
2116
}
2217

18+
protected initializeConsole() {
19+
this.siteSubscription = this.consoleService.getSite().subscribe(site => {
20+
this.site = site;
21+
this.updateDefaultDirectory();
22+
});
23+
this.publishingCredSubscription = this.consoleService.getPublishingCredentials().subscribe(publishingCredentials => {
24+
this.publishingCredentials = publishingCredentials;
25+
this.updateDefaultDirectory();
26+
});
27+
}
28+
2329
protected updateDefaultDirectory() {
24-
if (!this.site || !this.publishingCredentials) {
25-
return;
30+
if (this.site && this.publishingCredentials) {
31+
const uri = this.getKuduUri();
32+
const header = this.getHeader();
33+
const body = {
34+
'command': 'cd',
35+
'dir': 'site\\wwwroot'
36+
};
37+
const res = this.consoleService.send(HttpMethods.POST, uri, JSON.stringify(body), header);
38+
res.subscribe(data => {
39+
const output = data.json();
40+
this._defaultDirectory = output.Output.trim();
41+
this.dir = this._defaultDirectory;
42+
});
2643
}
27-
const uri = this.getKuduUri();
28-
const header = this.getHeader();
29-
const body = {
30-
'command': 'cd',
31-
'dir': 'site\\wwwroot'
32-
};
33-
const res = this.consoleService.send(HttpMethods.POST, uri, JSON.stringify(body), header);
34-
res.subscribe(data => {
35-
const output = data.json();
36-
this._defaultDirectory = output.Output.trim();
37-
this.dir = this._defaultDirectory;
38-
});
3944
}
4045

4146
/**

0 commit comments

Comments
 (0)