This repository was archived by the owner on Oct 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathoperator.component.ts
180 lines (150 loc) · 4.61 KB
/
operator.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { MatSnackBar } from '@angular/material';
import { pluck } from 'rxjs/operators';
import { CopierService } from '../../../core/services/copier.service';
import { SeoService } from '../../../core/services/seo.service';
import {
OperatorDoc,
OperatorReference,
OperatorExample,
OperatorExtra
} from '../../../../operator-docs/operator.model';
import { OperatorParameters } from '../../../../operator-docs';
import { OperatorsService } from '../../../core/services/operators.service';
import { Subscription } from 'rxjs';
@Component({
selector: 'app-operator',
templateUrl: './operator.component.html',
styleUrls: ['./operator.component.scss']
})
export class OperatorComponent implements OnInit, OnDestroy {
operatorsSubscription: Subscription;
noTranslation = false;
public operators: OperatorDoc[];
public operator: OperatorDoc;
public operatorsMap = new Map<string, OperatorDoc>();
private readonly baseSourceUrl = 'https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/';
private readonly baseSpecUrl = 'http://reactivex.io/rxjs/test-file/spec-js/operators';
constructor(
private _router: Router,
private _activatedRoute: ActivatedRoute,
private _seo: SeoService,
private _copierService: CopierService,
private _snackBar: MatSnackBar,
private _operatorsService: OperatorsService
) {}
ngOnInit() {
this.operatorsSubscription = this._operatorsService
.getOperators()
.subscribe(data => {
this.operatorsMap.clear();
this.operators = data;
this.operators.forEach((op: OperatorDoc) => {
this.operatorsMap.set(op.name, op);
});
this.setOperator();
});
}
setOperator(): void {
this._activatedRoute.params
.pipe(pluck('operator'))
.subscribe((name: string) => {
this.noTranslation = false;
if (this.operatorsMap.has(name)) {
this.operator = this.operatorsMap.get(name);
this.scrollToTop();
this.setHeaders();
} else {
this.setNotFoundOperator(name);
}
});
}
setNotFoundOperator(name: string): void {
this._operatorsService.getDefaultOperator(name).then(operator => {
if (operator) {
this.noTranslation = true;
this.operator = operator;
this.scrollToTop();
this.setHeaders();
return;
}
this.notFound();
});
}
setHeaders(): void {
this._seo.setHeaders({
title: [this.operator.name, this.operator.operatorType],
description: this.operator.shortDescription
? this.operator.shortDescription.description
: ''
});
}
scrollToTop() {
const content = document.querySelector('.mat-drawer-content');
if (content) {
content.scrollTop = 0;
}
}
copyToClipboard(code: string) {
this._copierService.copyText(code);
this._snackBar.open(
'The example has been copied to your clipboard!',
null,
{ duration: 3000 }
);
}
ngOnDestroy() {
this.operatorsSubscription.unsubscribe();
}
get operatorName() {
return this.operator.name;
}
get signature(): string {
return this.operator.signature || 'Signature Placeholder';
}
get marbleUrl(): string {
return this.operator.marbleUrl;
}
get useInteractiveMarbles(): boolean {
return this.operator.useInteractiveMarbles;
}
get shortDescription(): string {
return (
this.operator.shortDescription &&
this.operator.shortDescription.description
);
}
get shortDescriptionExtras(): OperatorExtra[] {
return (
this.operator.shortDescription && this.operator.shortDescription.extras
);
}
get walkthrough(): string {
return this.operator.walkthrough && this.operator.walkthrough.description;
}
get walkthroughExtras(): OperatorExtra[] {
return this.operator.walkthrough && this.operator.walkthrough.extras;
}
get parameters(): OperatorParameters[] {
return this.operator.parameters || [];
}
get examples(): OperatorExample[] {
return this.operator.examples || [];
}
get relatedOperators(): string[] {
return this.operator.relatedOperators || [];
}
get sourceUrl(): string {
return `${this.baseSourceUrl}/${this.operatorName}.ts`;
}
get specsUrl(): string {
return `${this.baseSpecUrl}/${this.operatorName}-spec.js.html`;
}
get additionalResources(): OperatorReference[] {
return this.operator.additionalResources || [];
}
private notFound(): void {
this._router.navigate(['/operators']);
}
}