Skip to content

Commit baba2fc

Browse files
committed
Fixed: Fix the issue with the tab name when splitting the name.
1 parent 20935f0 commit baba2fc

1 file changed

Lines changed: 41 additions & 19 deletions

File tree

src/app/services/view.ts

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,44 @@
1-
import {Injectable} from '@angular/core';
2-
import {View} from '@app/model';
3-
import {BehaviorSubject} from 'rxjs';
4-
import {FaceService} from '@app/services/face';
1+
import { View } from '@app/model';
2+
import { BehaviorSubject } from 'rxjs';
3+
import { Injectable } from '@angular/core';
4+
import { FaceService } from '@app/services/face';
55

66
@Injectable()
77
export class ViewService {
8-
viewList: Array<View> = [];
9-
currentView: View;
108
num = 0;
9+
10+
currentView: View;
11+
viewList: Array<View> = [];
1112
viewIds: Array<string> = [];
13+
14+
public state$ = new BehaviorSubject<any>({});
1215
public currentView$ = new BehaviorSubject<Object>({});
1316
private connectViewCount = new BehaviorSubject<number>(0);
17+
1418
public connectViewCount$ = this.connectViewCount.asObservable();
15-
public state$ = new BehaviorSubject<any>({});
1619

17-
constructor(private _faceSvc: FaceService) {
18-
}
20+
constructor(private _faceSvc: FaceService) {}
1921

2022
addView(view: View) {
2123
this.num += 1;
24+
2225
view.id = 'View_' + this.num;
26+
2327
this.viewList.push(view);
2428
this.viewIds.push(view.id);
2529

2630
if (view.connectToken.face_monitor_token) {
2731
this._faceSvc.addMonitoringTab(view.id);
2832
}
29-
this.state$.next({action: 'add', view: view});
33+
34+
this.state$.next({ action: 'add', view: view });
3035
}
3136

3237
activeView(view: View) {
3338
this.viewList.forEach((v, k) => {
3439
if (v === view) {
3540
v.active = true;
41+
3642
if (view.termComp && typeof view.termComp.setActive === 'function') {
3743
setTimeout(() => {
3844
view.termComp.setActive();
@@ -44,55 +50,66 @@ export class ViewService {
4450
});
4551
setTimeout(() => {
4652
const viewEl = document.getElementById(view.id);
53+
4754
if (viewEl) {
4855
viewEl.scrollIntoView();
4956
}
5057
}, 100);
58+
5159
this.currentView = view;
5260
this.setCurrentView(view);
5361
}
5462

5563
removeView(view: View) {
5664
const index = this.viewList.indexOf(view);
57-
this.viewList.splice(index, 1);
5865
const idIndex = this.viewIds.indexOf(view.id);
66+
67+
this.viewList.splice(index, 1);
5968
this.viewIds.splice(idIndex, 1);
69+
6070
if (this.viewList.length === 0) {
6171
this.setCurrentView({});
6272
}
6373
if (view.connectToken.face_monitor_token) {
6474
this._faceSvc.removeMonitoringTab(view.id);
6575
}
66-
this.state$.next({action: 'close', view: view});
76+
77+
this.state$.next({ action: 'close', view: view });
6778
}
6879

6980
addSubViewToCurrentView(view: View) {
7081
this.currentView.subViews.push(view);
82+
7183
const index = this.currentView.subViews.length;
72-
this.setCurrentViewTitle(view, index + 1, 'concat');
84+
85+
this.setCurrentViewTitle(view, index, 'concat');
7386
this.setCurrentView();
74-
this.state$.next({action: 'addSub', view: view, currentView: this.currentView});
87+
this.state$.next({ action: 'addSub', view: view, currentView: this.currentView });
7588
}
7689

7790
clearSubViewOfCurrentView(view: View) {
7891
const index = this.currentView.subViews.indexOf(view);
92+
7993
this.currentView.subViews.splice(index, 1);
80-
this.setCurrentViewTitle(view, index + 1, 'delete');
94+
this.setCurrentViewTitle(view, index, 'delete');
8195
this.setCurrentView();
82-
this.state$.next({action: 'clearSub', view: view, currentView: this.currentView});
96+
this.state$.next({ action: 'clearSub', view: view, currentView: this.currentView });
8397
}
8498

8599
setCurrentViewTitle(view, index, status) {
86-
const {name} = this.currentView;
100+
const { name } = this.currentView;
101+
87102
switch (status) {
88103
case 'concat':
89104
this.currentView.name = name + '|' + view.name;
90105
break;
91106
case 'delete':
92107
const names = name.split('|');
108+
93109
if (names[index] === view.name) {
94110
names.splice(index, 1);
95111
}
112+
96113
this.currentView.name = names.join('|');
97114
break;
98115
}
@@ -102,8 +119,10 @@ export class ViewService {
102119
keyboardSwitchTab(key) {
103120
let nextViewId: any = 0;
104121
let nextActiveView = null;
122+
105123
const viewIds = this.viewIds;
106124
const currentViewIndex = viewIds.findIndex(i => i === this.currentView.id);
125+
107126
if (key === 'alt+shift+right') {
108127
if (currentViewIndex === viewIds.length - 1 && currentViewIndex !== 0) {
109128
nextActiveView = this.viewList.find(i => i.id === viewIds[0]);
@@ -128,9 +147,12 @@ export class ViewService {
128147
setCurrentView(view: Object = this.currentView) {
129148
this.currentView$.next(view);
130149
const connectedCount = this.viewList.filter(
131-
v => v.connected === true && v.connectMethod.component === 'koko' && v.connectMethod.value === 'web_cli'
150+
v =>
151+
v.connected === true &&
152+
v.connectMethod.component === 'koko' &&
153+
v.connectMethod.value === 'web_cli'
132154
).length;
133155
this.connectViewCount.next(connectedCount);
134-
this.state$.next({action: 'active', view: view});
156+
this.state$.next({ action: 'active', view: view });
135157
}
136158
}

0 commit comments

Comments
 (0)