src/app/stations/stations-props-manager.ts
Compbaser
host | { |
selector | stations-props-manager |
styles |
ul {
padding: 0px;
}
#stationcontrol {
width: 100%;
}
#stationcontrol button {
width: 25%;
}
/*.loading {*/
/*float: left;*/
/*position: relative;*/
/*top: -106px;*/
/*left: calc((100% / 2) - 30px);*/
/*}*/
/*img {*/
/*float: left;*/
/*position: relative;*/
/*width: 210px;*/
/*top: -140px;*/
/*left: calc((100% / 2) - 109px);*/
/*}*/
/*#propWrap {*/
/*position: fixed;*/
/*padding-left: 20px;*/
/*}*/
|
templateUrl | ./stations-props-manager.html |
constructor(toast: ToastsManager, fb: FormBuilder, yp: YellowPepperService, rp: RedPepperService, cd: ChangeDetectorRef)
|
loadImage |
loadImage(imagePath: string)
|
Returns :
Observable<HTMLImageElement>
|
_resetSnapshotSelection |
_resetSnapshotSelection()
|
Returns :
void
|
_render |
_render()
|
Returns :
void
|
_onFocus |
_onFocus(i_value: any)
|
Returns :
void
|
_onStationRename |
_onStationRename()
|
Returns :
void
|
_onCommand |
_onCommand(i_command: any)
|
Returns :
void
|
_onLoaded |
_onLoaded()
|
Returns :
void
|
_onError |
_onError()
|
Returns :
void
|
_onCompleted |
_onCompleted()
|
Returns :
void
|
_takeSnapshot |
_takeSnapshot()
|
Returns :
void
|
_onSendEvent |
_onSendEvent()
|
Returns :
void
|
Protected saveToStore |
saveToStore()
|
Decorators : timeout
|
Returns :
void
|
destroy |
destroy()
|
Returns :
void
|
contGroup |
contGroup: |
lazyImage |
lazyImage: |
Decorators : ViewChild
|
m_campaigns |
m_campaigns: |
m_disabled |
m_disabled: |
Default value : true
|
m_inFocus |
m_inFocus: |
Default value : false
|
m_ip |
m_ip: |
m_loading |
m_loading: |
Default value : false
|
m_port |
m_port: |
m_selectedBranchStation |
m_selectedBranchStation: |
m_selectedCampaignId |
m_selectedCampaignId: |
m_selectedStation |
m_selectedStation: |
m_sideProps$ |
m_sideProps$: |
m_sidePropsEnum |
m_sidePropsEnum: |
Default value : SideProps
|
m_snapPath |
m_snapPath: |
m_uiUserFocusItem$ |
m_uiUserFocusItem$: |
shouldToggle |
shouldToggle: |
Default value : true
|
import {ChangeDetectorRef, Component, ViewChild} from "@angular/core";
import {Compbaser} from "ng-mslib";
import {Observable} from "rxjs";
import {ACTION_LIVELOG_UPDATE, SideProps} from "../../store/actions/appdb.actions";
import {YellowPepperService} from "../../services/yellowpepper.service";
import {RedPepperService} from "../../services/redpepper.service";
import {StationModel} from "../../models/StationModel";
import {animate, state, style, transition, trigger} from "@angular/animations";
import {FormBuilder, FormGroup} from "@angular/forms";
import {timeout} from "../../decorators/timeout-decorator";
import {BranchStationsModelExt, CampaignsModelExt} from "../../store/model/msdb-models-extended";
import {List} from "immutable";
import {Http} from "@angular/http";
import {LazyImage} from "../../comps/lazy-image/lazy-image";
import {ToastsManager} from "ng2-toastr";
import {LiveLogModel} from "../../models/live-log-model";
@Component({
selector: 'stations-props-manager',
host: {
'(input-blur)': 'saveToStore($event)'
},
animations: [
trigger('toggleState', [
state('true', style({})),
state('false', style({maxHeight: 0, padding: 0, display: 'none'})),
// transition
transition('* => *', animate('300ms')),
])
],
styles: [`
ul {
padding: 0px;
}
#stationcontrol {
width: 100%;
}
#stationcontrol button {
width: 25%;
}
/*.loading {*/
/*float: left;*/
/*position: relative;*/
/*top: -106px;*/
/*left: calc((100% / 2) - 30px);*/
/*}*/
/*img {*/
/*float: left;*/
/*position: relative;*/
/*width: 210px;*/
/*top: -140px;*/
/*left: calc((100% / 2) - 109px);*/
/*}*/
/*#propWrap {*/
/*position: fixed;*/
/*padding-left: 20px;*/
/*}*/
`],
templateUrl: './stations-props-manager.html'
})
export class StationsPropsManager extends Compbaser {
contGroup: FormGroup;
m_sideProps$: Observable<SideProps>;
m_sidePropsEnum = SideProps;
m_uiUserFocusItem$: Observable<SideProps>;
m_selectedStation: StationModel;
m_selectedBranchStation: BranchStationsModelExt;
m_selectedCampaignId = -1;
m_loading = false;
m_snapPath = '';
shouldToggle = true;
m_disabled = true;
m_port = '';
m_campaigns: List<CampaignsModelExt>;
m_ip = '';
m_inFocus = false;
constructor(private toast: ToastsManager, private fb: FormBuilder, private yp: YellowPepperService, private rp: RedPepperService, private cd: ChangeDetectorRef) {
super();
this.m_uiUserFocusItem$ = this.yp.ngrxStore.select(store => store.appDb.uiState.uiSideProps);
this.m_sideProps$ = this.yp.ngrxStore.select(store => store.appDb.uiState.uiSideProps);
this.contGroup = fb.group({
'm_campaignsControl': [''],
'm_stationName': [''],
'm_eventValue': [''],
'm_enableLan': [],
'm_ip': [],
'm_port': []
});
this.cancelOnDestroy(
//
this.yp.getCampaigns()
.subscribe((i_campaigns: List<CampaignsModelExt>) => {
this.m_campaigns = i_campaigns;
}, (e) => console.error(e))
)
this.cancelOnDestroy(
//
this.yp.listenStationBranchSelected()
.map((i_station: StationModel) => {
this.m_snapPath = '';
if (this.m_selectedStation && this.m_selectedStation.id != i_station.id)
this._resetSnapshotSelection();
this.m_selectedStation = i_station;
this.m_disabled = this.m_selectedStation.connection == "0";
return this.m_selectedStation.id;
})
.mergeMap(i_station_id => {
return this.yp.getStationCampaignID(i_station_id)
.map((i_campaign_id) => {
return {i_station_id, i_campaign_id};
})
})
.mergeMap(({i_station_id, i_campaign_id}) => {
this.m_selectedCampaignId = i_campaign_id;
return this.yp.listenStationRecord(i_station_id)
})
.subscribe((i_branchStationsModel) => {
this.m_selectedBranchStation = i_branchStationsModel;
this._render()
}, (e) => console.error(e))
)
}
@ViewChild(LazyImage)
lazyImage: LazyImage;
loadImage(imagePath: string): Observable<HTMLImageElement> {
return Observable
.create(observer => {
const img = new Image();
try {
img.src = imagePath;
img.onload = () => {
observer.next(imagePath);
observer.complete();
};
img.onerror = err => {
observer.error(null);
};
}
catch (e) {
console.log('some error ' + e);
}
});
}
_resetSnapshotSelection() {
if (this.lazyImage)
this.lazyImage.resetToDefault();
}
_render() {
if (!this.m_selectedBranchStation)
return;
this.contGroup.controls.m_campaignsControl.setValue(this.m_selectedCampaignId);
this.contGroup.controls.m_enableLan.setValue(this.m_selectedBranchStation.getLanEnabled);
if (this.m_inFocus)
return;
this.contGroup.controls.m_stationName.setValue(this.m_selectedBranchStation.getStationName());
this.contGroup.controls.m_ip.setValue(this.m_selectedBranchStation.getLanServerIp());
this.contGroup.controls.m_port.setValue(this.m_selectedBranchStation.getLanServerPort());
}
_onFocus(i_value) {
this.m_inFocus = i_value;
}
_onStationRename(){
this.toast.info('Station name will apply a few minutes after you save Studio changes, click [Save]');
}
_onCommand(i_command) {
this.yp.dispatch(({type: ACTION_LIVELOG_UPDATE, payload: new LiveLogModel({event: 'send station event ' + i_command})}));
switch (i_command) {
case 'play': {
this.rp.sendCommand('start', this.m_selectedStation.id, () => {
});
break;
}
case 'stop': {
this.rp.sendCommand('stop', this.m_selectedStation.id, () => {
});
break;
}
case 'snap': {
this._takeSnapshot();
break;
}
case 'off': {
this.rp.sendCommand('rebootPlayer', this.m_selectedStation.id, () => {
});
break;
}
}
}
_onLoaded() {
console.log('img loaded');
}
_onError(){
console.log('img error');
}
_onCompleted() {
console.log('img completed');
}
_takeSnapshot() {
var d = new Date().getTime();
this.m_snapPath = '';
this.m_loading = true;
var path = this.rp.sendSnapshot(d, 0.2, this.m_selectedStation.id, () => {
this.m_snapPath = path;
this.lazyImage.urls = [path];
});
setTimeout(() => {
this.loadImage(path)
.subscribe(v => {
// console.log(v);
})
}, 100)
setTimeout(() => {
this.m_loading = false;
this.m_snapPath = path;
// console.log('loading image from ' + this.m_snapPath);
}, 100);
}
_onSendEvent() {
this.shouldToggle != this.shouldToggle;
this.rp.sendEvent(this.contGroup.controls.m_eventValue.value, this.m_selectedStation.id, function () {
});
this.yp.dispatch(({type: ACTION_LIVELOG_UPDATE, payload: new LiveLogModel({event: 'send station event ' + this.contGroup.controls.m_eventValue.value})}));
}
@timeout()
private saveToStore() {
// console.log(this.contGroup.status + ' ' + JSON.stringify(this.ngmslibService.cleanCharForXml(this.contGroup.value)));
if (this.contGroup.status != 'VALID')
return;
if (this.contGroup.value.m_ip.match(/\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}\b/))
this.rp.setStationRecordValue(this.m_selectedStation.id, 'lan_server_ip', this.contGroup.value.m_ip);
this.rp.setStationCampaignID(this.m_selectedStation.id, this.contGroup.value.m_campaignsControl);
this.rp.setStationRecordValue(this.m_selectedStation.id, 'lan_server_enabled', this.contGroup.value.m_enableLan == true ? 'True' : 'False');
this.rp.setStationRecordValue(this.m_selectedStation.id, 'lan_server_port', this.contGroup.value.m_port);
this.rp.setStationName(this.m_selectedStation.id, this.contGroup.value.m_stationName);
this.rp.reduxCommit();
this.cd.markForCheck();
}
destroy() {
}
}
<small class="debug">{{me}}</small>
<hr/>
<form matchBodyHeight="150" style="overflow-y: auto; overflow-x: hidden" novalidate autocomplete="off" [formGroup]="contGroup">
<ul [ngSwitch]="m_sideProps$ | async">
<div *ngSwitchCase="m_sidePropsEnum.stationProps">
<div id="stationProperties">
<img lazyImage class="center-block" style="width: 229px; height: 130px"
[loadingImage]="'https://secure.digitalsignage.com/studioweb/assets/screen_loading.png'"
[defaultImage]="'https://secure.digitalsignage.com/studioweb/assets/screen.png'"
[errorImage]="'https://secure.digitalsignage.com/studioweb/assets/screen_error.png'"
[retry]="5"
[delay]="1500"
(loaded)="_onLoaded()"
(error)="_onError()"
(completed)="_onCompleted()">
<!--<div id="snapShotWrap">-->
<!--<img lazyImage [url]="'http://s3-us-west-2.amazonaws.com/oregon-signage-snapshots/business358613/station75/_1491055107002.jpg'">-->
<!--<div style="text-align: center">-->
<!--<svg style="width: 250px" xmlns="http://www.w3.org/2000/svg">-->
<!--<g>-->
<!--<rect stroke-width="10" stroke="#191919" height="120" width="220" y="9.5" x="10" fill="#cccccc"></rect>-->
<!--</g>-->
<!--</svg>-->
<!--</div>-->
<!--<div style="text-align: center">-->
<!--<loading class="loading" [size]="'50px'" *ngIf="m_loading"></loading>-->
<!--</div>-->
<!--<div *ngIf="m_snapPath != ''" style="text-align: center">-->
<!--<img (error)="_onImageError($event)" [src]="m_snapPath"/>-->
<!--</div>-->
<!--</div>-->
<hr/>
<div id="propWrap">
<div id="stationcontrol" class="btn-group">
<button (click)="_onCommand('snap')" [disabled]="m_disabled" type="button" class="btn btn-default">
<span class="glyphicon glyphicon glyphicon-picture"></span>
</button>
<button (click)="_onCommand('play')" [disabled]="m_disabled" type="button" class="btn btn-default">
<span class="glyphicon glyphicon glyphicon-play"></span>
</button>
<button (click)="_onCommand('stop')" [disabled]="m_disabled" type="button" class="btn btn-default">
<span class="glyphicon glyphicon glyphicon-stop"></span>
</button>
<button (click)="_onCommand('off')" [disabled]="m_disabled" type="button" class="btn btn-default">
<span class="fa fa-power-off"></span>
</button>
</div>
<select (change)="saveToStore()" formControlName="m_campaignsControl" id="stationSelectionCampaign" class="form-control">
<option [value]="campaign.getCampaignId()" *ngFor="let campaign of m_campaigns">{{campaign.getCampaignName()}}</option>
</select>
<br/>
<Label>Station name</Label>
<input (change)="_onStationRename()" (focus)="_onFocus(true)" (blur)="_onFocus(false)" formControlName="m_stationName" type="text">
<hr/>
<div id="stationInfo">
<ul *ngIf="m_selectedStation">
<li>
<span>Name </span>: {{m_selectedStation.name}}
</li>
<li>
<span>Station id: </span>: {{m_selectedStation.id}}
</li>
<li>
<span>OS </span>: {{m_selectedStation.os}}
</li>
<li>
<span>AIR </span>: {{m_selectedStation.airVersion}}
</li>
<li>
<span>App version: </span>: {{m_selectedStation.appVersion}}
</li>
<li>
<span>Peak memory: </span>: {{m_selectedStation.peakMemory}}
</li>
<li>
<span>Total memory: </span>: {{m_selectedStation.totalMemory}}
</li>
<li>
<span>Running: </span>: {{m_selectedStation.runningTime}}
</li>
<li>
<span>Watchdog: </span>: {{m_selectedStation.watchDogConnection == "1" ? 'ON' : 'OFF'}}
</li>
<li>
<span>Last update: </span>: {{m_selectedStation.lastUpdate}}
</li>
</ul>
</div>
<br/>
<br/>
<Label>Station events</Label>
<input formControlName="m_eventValue" type="text" name="eventName" data-localize="eventName" placeholder="event name" id="stationSendEventValue" value="">
<p></p>
<button (click)="_onSendEvent()" [@toggleState]="shouldToggle" id="stationEventSendCommand" class="btn btn-primary"><i class="fa fa-paper-plane"></i> Send event to remote station
</button>
<hr/>
<div>
<label class="pull-left" data-localize="serverMode">server mode (listen to local
events)</label>
<div class="clearfix" style="padding-bottom: 13px"></div>
<div style="position: relative; top: -12px" class="material-switch pull-left">
<input (change)="saveToStore()" formControlName="m_enableLan" id="stationServerMode" name="someSwitchOption001" type="checkbox"/>
<label for="stationServerMode" class="label-primary"></label>
</div>
</div>
<div class="clearfix"></div>
<div *ngIf="m_selectedBranchStation && m_selectedBranchStation.getLanEnabled" class="row">
<ul class="list-group">
<li class="list-group-item">
<span i18n class="inliner">ip address</span>
<input (focus)="_onFocus(true)" (blur)="_onFocus(false)" formControlName="m_ip" type="text" class="numStepper inliner">
</li>
<li class="list-group-item">
<span i18n class="inliner">port</span>
<input (focus)="_onFocus(true)" (blur)="_onFocus(false)" formControlName="m_port" type="number" step="1" class="numStepper inliner">
</li>
</ul>
</div>
</div>
</div>
</div>
<div *ngSwitchCase="m_sidePropsEnum.miniDashboard">
<dash-panel-mini></dash-panel-mini>
</div>
</ul>
</form>