web-remote/src/app/search.component.ts

67 lines
1.9 KiB
TypeScript
Raw Normal View History

import { Component, OnInit } from '@angular/core';
import { OpenLPService } from './openlp.service';
2018-08-20 00:00:32 +00:00
import { PluginDescription } from './responses';
@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>
<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">
{{plugin.name}}
</mat-option>
</mat-select>
2018-08-20 00:00:32 +00:00
</mat-form-field>
<br>
<mat-form-field>
2018-08-19 23:07:17 +00:00
<input matInput [(ngModel)]="searchText" name="searchText" placeholder="Search Text">
</mat-form-field>
<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>
</tr>
</table>
</div>
`,
providers: [OpenLPService]
})
export class OpenLPSearchComponent implements OnInit {
2018-08-20 00:00:32 +00:00
public searchPlugins: PluginDescription[] = [];
public searchText = null;
public searchResults = null;
2018-08-20 12:30:23 +00:00
public selectedPlugin: string = "songs";
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);
}
sendLive(id) {
2018-08-20 13:25:28 +00:00
this.openlpService.sendItemLive(this.currentPlugin, id).subscribe(res => console.log(res));
}
addToService(id) {
2018-08-20 13:25:28 +00:00
this.openlpService.addItemToService(this.currentPlugin, id).subscribe(res => console.log(res));
}
ngOnInit() {
2018-08-20 00:00:32 +00:00
this.openlpService.getSearchablePlugins().subscribe(items => this.searchPlugins = items);
}
2018-08-20 00:00:32 +00:00
}