Merge branch 'master' into settings-section

This commit is contained in:
Mateus Meyer Jiacomelli 2023-02-09 15:52:03 -03:00
commit 31c6736c54
4 changed files with 86 additions and 17 deletions

View File

@ -15,14 +15,54 @@ export class ChordViewComponent extends StageViewComponent {
// current songs transpose level // current songs transpose level
transposeLevel = 0; transposeLevel = 0;
stageProperty = 'chords'; stageProperty = 'chords';
currentSlide = 0;
useNewTransposeEndpoint = this.openlpService.assertApiVersionMinimum(2, 2);
updateCurrentSlides(serviceItemId: string, currentSlide: number): void {
this.currentSlide = currentSlide;
this.useNewTransposeEndpoint = this.openlpService.assertApiVersionMinimum(2, 2);
this.serviceItemSubscription$?.unsubscribe();
const newServiceItemTransposeLevel = this.songTransposeMap.get(serviceItemId);
setNewSlides(slides: Slide[]): void { if (this.useNewTransposeEndpoint && newServiceItemTransposeLevel && (newServiceItemTransposeLevel !== 0)) {
super.setNewSlides(slides); this.transposeLevel = newServiceItemTransposeLevel;
this.serviceItemSubscription$ = this.openlpService
.transposeSong(newServiceItemTransposeLevel, 'service_item')
.subscribe(serviceItem => {
this.serviceItem = serviceItem;
if (serviceItem instanceof Array) {
this.setNewSlides(serviceItem, currentSlide);
}
else {
this.setNewSlides(serviceItem.slides, currentSlide);
this.setNotes(serviceItem.notes);
}
});
} else {
if (this.useNewTransposeEndpoint) {
this.songTransposeMap.set(serviceItemId, 0);
this.transposeLevel = 0;
}
super.updateCurrentSlides(serviceItemId, currentSlide);
}
}
setNewSlides(slides: Slide[], currentSlide: number): void {
if (this.openlpService.assertApiVersionExact(2, 2)) {
// API Version 2.2 released on OpenLP 3.0.2 contains a bug on which 'selected' is not set correctly
// on Transponse Service Item response.
if (slides[currentSlide]) {
slides[currentSlide].selected = true;
}
}
super.setNewSlides(slides, currentSlide);
// if this song is already known // if this song is already known
if (this.songTransposeMap.has(this.serviceItem.id)) { if (this.songTransposeMap.has(this.serviceItem.id)) {
if (this.songTransposeMap.get(this.serviceItem.id) !== 0) { const transposeLevel = this.songTransposeMap.get(this.serviceItem.id);
this.transposeChords(); if (transposeLevel) {
if (!this.useNewTransposeEndpoint) {
this.transposeChords();
}
} else { } else {
this.transposeLevel = this.songTransposeMap.get(this.serviceItem.id); this.transposeLevel = this.songTransposeMap.get(this.serviceItem.id);
} }
@ -56,7 +96,15 @@ export class ChordViewComponent extends StageViewComponent {
transposeChords(): void { transposeChords(): void {
const tmpTranspose = this.songTransposeMap.get(this.serviceItem.id); const tmpTranspose = this.songTransposeMap.get(this.serviceItem.id);
this.transposeLevel = tmpTranspose; this.transposeLevel = tmpTranspose;
this.openlpService.transposeSong(tmpTranspose).subscribe(transposedLyrics => { if (this.useNewTransposeEndpoint) {
this.updateCurrentSlides(this.serviceItem.id, this.currentSlide);
} else {
this.transposeChordsLegacy(tmpTranspose);
}
}
transposeChordsLegacy(transposeLevel): void {
this.openlpService.transposeSong(transposeLevel).subscribe(transposedLyrics => {
// Replace the chords in the currentSlides with the returned transposed chords // Replace the chords in the currentSlides with the returned transposed chords
if (transposedLyrics instanceof Array) { if (transposedLyrics instanceof Array) {
for (let i = 0; i < transposedLyrics.length; ++i) { for (let i = 0; i < transposedLyrics.length; ++i) {

View File

@ -26,7 +26,8 @@ export class StageViewComponent implements OnInit, OnDestroy {
time = new Date(); time = new Date();
showNotes = true; showNotes = true;
fontScale: number; fontScale: number;
serviceItemSubscription$: Subscription = null;
fontScaleSubscription$: Subscription; fontScaleSubscription$: Subscription;
stageProperty = 'stage'; stageProperty = 'stage';
@ -41,8 +42,8 @@ export class StageViewComponent implements OnInit, OnDestroy {
} }
ngOnInit() { ngOnInit() {
this.updateCurrentSlides(); this.updateCurrentSlides(null, null);
this.openlpService.stateChanged$.subscribe(item => this.updateCurrentSlides()); this.openlpService.stateChanged$.subscribe(item => this.updateCurrentSlides(item.item, item.slide));
this.fontScale = this.settingsService.get( this.fontScale = this.settingsService.get(
this.stageProperty + 'FontScale' as keyof SettingsProperties this.stageProperty + 'FontScale' as keyof SettingsProperties
) as number / 100; ) as number / 100;
@ -59,14 +60,15 @@ export class StageViewComponent implements OnInit, OnDestroy {
this.fontScaleSubscription$?.unsubscribe(); this.fontScaleSubscription$?.unsubscribe();
} }
updateCurrentSlides(): void { updateCurrentSlides(serviceItemId: string, currentSlide: number): void {
this.openlpService.getServiceItem().subscribe(serviceItem => { this.serviceItemSubscription$?.unsubscribe();
this.serviceItemSubscription$ = this.openlpService.getServiceItem().subscribe(serviceItem => {
this.serviceItem = serviceItem; this.serviceItem = serviceItem;
if (serviceItem instanceof Array) { if (serviceItem instanceof Array) {
this.setNewSlides(serviceItem); this.setNewSlides(serviceItem, currentSlide);
} }
else { else {
this.setNewSlides(serviceItem.slides); this.setNewSlides(serviceItem.slides, currentSlide);
this.setNotes(serviceItem.notes); this.setNotes(serviceItem.notes);
} }
}); });
@ -76,7 +78,7 @@ export class StageViewComponent implements OnInit, OnDestroy {
return this.currentSlides.slice(this.activeSlide + 1); return this.currentSlides.slice(this.activeSlide + 1);
} }
setNewSlides(slides: Slide[]): void { setNewSlides(slides: Slide[], currentSlide: number): void {
if (slides.length === 0) { if (slides.length === 0) {
return; return;
} }

View File

@ -1,7 +1,7 @@
import { Injectable, EventEmitter } from '@angular/core'; import { Injectable, EventEmitter } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http'; import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable, Subscription } from 'rxjs'; import { Observable, Subscription } from 'rxjs';
import { finalize, shareReplay } from 'rxjs/operators'; import { finalize, shareReplay, tap } from 'rxjs/operators';
import { import {
PluginDescription, PluginDescription,
@ -44,6 +44,8 @@ export enum WebSocketStatus {
@Injectable() @Injectable()
export class OpenLPService { export class OpenLPService {
private apiURL: string; private apiURL: string;
public apiVersion: number | null;
public apiRevision: number | null;
private host: string; private host: string;
public stateChanged$: EventEmitter<State>; public stateChanged$: EventEmitter<State>;
public webSocketStateChanged$: EventEmitter<WebSocketStatus>; public webSocketStateChanged$: EventEmitter<WebSocketStatus>;
@ -69,6 +71,14 @@ export class OpenLPService {
this.createWebSocket(); this.createWebSocket();
} }
assertApiVersionExact(version: number, revision: number) {
return version === this.apiVersion && revision === this.apiRevision;
}
assertApiVersionMinimum(version: number, revision: number) {
return this.apiVersion >= version && this.apiRevision >= revision;
}
setAuthToken(token: string): void { setAuthToken(token: string): void {
httpOptions.headers = httpOptions.headers.set('Authorization', token); httpOptions.headers = httpOptions.headers.set('Authorization', token);
} }
@ -78,7 +88,13 @@ export class OpenLPService {
} }
retrieveSystemInformation(): Observable<SystemInformation> { retrieveSystemInformation(): Observable<SystemInformation> {
return this.doGet<SystemInformation>(`${this.apiURL}/core/system`); return this.doGet<SystemInformation>(`${this.apiURL}/core/system`)
.pipe(tap(systemInfo => {
if (systemInfo.api_version) {
this.apiVersion = systemInfo.api_version;
this.apiRevision = systemInfo.api_revision;
}
}));
} }
getMainImage(): Observable<MainView> { getMainImage(): Observable<MainView> {
@ -185,8 +201,8 @@ export class OpenLPService {
return this.doPost(`${this.apiURL}/plugins/${plugin}/add`, {id}); return this.doPost(`${this.apiURL}/plugins/${plugin}/add`, {id});
} }
transposeSong(transpose_value): Observable<any> { transposeSong(transpose_value, return_format = 'default'): Observable<any> {
return this.doGet(`${this.apiURL}/plugins/songs/transpose-live-item/${transpose_value}`); return this.doGet(`${this.apiURL}/plugins/songs/transpose-live-item/${transpose_value}?response_format=${return_format}`);
} }
login(credentials: Credentials): Observable<AuthToken> { login(credentials: Credentials): Observable<AuthToken> {

View File

@ -12,6 +12,7 @@ export class State {
blank: boolean; blank: boolean;
twelve: boolean; twelve: boolean;
theme: boolean; theme: boolean;
item: string;
live = () => !(this.blank || this.display || this.theme); live = () => !(this.blank || this.display || this.theme);
@ -68,6 +69,8 @@ export interface MainView {
export interface SystemInformation { export interface SystemInformation {
websocket_port: number; websocket_port: number;
login_required: boolean; login_required: boolean;
api_version?: number;
api_revision?: number;
} }
export interface Credentials { export interface Credentials {