2018-08-19 20:37:53 +00:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
import { OpenLPService } from './openlp.service';
|
2018-08-20 00:00:32 +00:00
|
|
|
import { PluginDescription } from './responses';
|
2018-08-19 20:37:53 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'openlp-remote-search',
|
|
|
|
template: `
|
|
|
|
<h3>Search</h3>
|
|
|
|
<form>
|
|
|
|
<label>Search for:</label>
|
2018-08-20 00:00:32 +00:00
|
|
|
<mat-form-field>
|
2018-08-19 20:37:53 +00:00
|
|
|
<mat-select [(ngModel)]="selectedPlugin" name="selectedPlugin">
|
2018-08-20 00:00:32 +00:00
|
|
|
<mat-option *ngFor="let plugin of searchPlugins" name="searchPlugins" [value]="plugin.key">
|
2018-08-19 20:37:53 +00:00
|
|
|
{{plugin.name}}
|
|
|
|
</mat-option>
|
|
|
|
</mat-select>
|
2018-08-20 00:00:32 +00:00
|
|
|
</mat-form-field>
|
2018-08-19 20:37:53 +00:00
|
|
|
<br>
|
|
|
|
<mat-form-field>
|
2018-08-19 23:07:17 +00:00
|
|
|
<input matInput [(ngModel)]="searchText" name="searchText" placeholder="Search Text">
|
|
|
|
</mat-form-field>
|
2018-08-19 20:37:53 +00:00
|
|
|
<br>
|
|
|
|
<button mat-raised-button color="warn" (click)="onSubmit()">Search</button>
|
|
|
|
</form>
|
|
|
|
<div *ngIf="searchResults">
|
|
|
|
<h3>Search Results:</h3>
|
|
|
|
<table>
|
|
|
|
<tr *ngFor="let item of searchResults">
|
|
|
|
<td>{{item[1]}}</td>
|
2018-08-20 12:30:23 +00:00
|
|
|
<td><button mat-button color="primary" (click)="addToService(item[0])">Add</button></td>
|
|
|
|
<td><button mat-button color="accent" (click)="sendLive(item[0])">Send Live</button></td>
|
2018-08-19 20:37:53 +00:00
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
`,
|
|
|
|
providers: [OpenLPService]
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
export class OpenLPSearchComponent implements OnInit {
|
|
|
|
|
2018-08-20 00:00:32 +00:00
|
|
|
public searchPlugins: PluginDescription[] = [];
|
2018-08-19 20:37:53 +00:00
|
|
|
public searchText = null;
|
|
|
|
public searchResults = null;
|
2018-08-20 12:30:23 +00:00
|
|
|
public selectedPlugin: string = "songs";
|
2018-08-19 20:37:53 +00:00
|
|
|
public currentPlugin: string;
|
|
|
|
|
|
|
|
constructor(private openlpService: OpenLPService) {}
|
|
|
|
|
|
|
|
onSubmit() {
|
|
|
|
this.currentPlugin = this.selectedPlugin;
|
2018-08-20 00:00:32 +00:00
|
|
|
this.currentPlugin = "songs";
|
|
|
|
this.openlpService.search(this.currentPlugin, this.searchText).subscribe(items => this.searchResults = items);
|
2018-08-19 20:37:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sendLive(id) {
|
2018-08-20 13:25:28 +00:00
|
|
|
this.openlpService.sendItemLive(this.currentPlugin, id).subscribe(res => console.log(res));
|
2018-08-19 20:37:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addToService(id) {
|
2018-08-20 13:25:28 +00:00
|
|
|
this.openlpService.addItemToService(this.currentPlugin, id).subscribe(res => console.log(res));
|
2018-08-19 20:37:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2018-08-20 00:00:32 +00:00
|
|
|
this.openlpService.getSearchablePlugins().subscribe(items => this.searchPlugins = items);
|
2018-08-19 20:37:53 +00:00
|
|
|
}
|
2018-08-20 00:00:32 +00:00
|
|
|
}
|