Skip to content

Commit

Permalink
feat: support for multiple think tank
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Apr 18, 2020
1 parent 41226a0 commit f6ccb2f
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class LedgeChecklistComponent implements OnInit, OnChanges {
subitems: []
};
for (const child of item.children) {
console.log(child);
const splitName = child.name.split(':');
checklist.subitems.push({
title: splitName[0],
Expand Down
12 changes: 10 additions & 2 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,18 @@
<button mat-button routerLink="/practise" routerLinkActive="active">{{ 'practises' | translate}}</button>
<button mat-button routerLink="/manual" routerLinkActive="active">{{ 'manual' | translate}}</button>
<button mat-button routerLink="/solution" routerLinkActive="active">{{ 'solution' | translate}}</button>
<button mat-button routerLink="/think-tank" routerLinkActive="active">{{ 'think-tank' | translate}}</button>

<mat-menu #tankMenu="matMenu" backdropClass="nav-menu-wrapper">
<button mat-menu-item routerLink="/think-tank/qa" routerLinkActive="active">QA {{ 'think-tank' | translate}}</button>
<button mat-menu-item routerLink="/think-tank/mobile-android" routerLinkActive="active">Android {{ 'think-tank' | translate}}</button>
</mat-menu>

<button mat-button [matMenuTriggerFor]="tankMenu">
{{ 'think-tank' | translate}}
<mat-icon>arrow_drop_down</mat-icon>
</button>

<mat-menu #appMenu="matMenu" backdropClass="nav-menu-wrapper">
<button mat-menu-item routerLink="/mobile" routerLinkActive="active">{{ 'mobile' | translate}}</button>
<button mat-menu-item routerLink="/maturity" routerLinkActive="active">{{ 'maturity' | translate}}</button>
<button mat-menu-item routerLink="/report" routerLinkActive="active">{{ 'report' | translate}}</button>
<button mat-menu-item routerLink="/resources" routerLinkActive="active">{{ 'resources' | translate}}</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ export class MarkdownRenderComponent
this.render();
}

ngOnChanges(changes: SimpleChanges): void {}
ngOnChanges(changes: SimpleChanges): void {
if (changes.data) {
this.markdownService.compile(changes.data.currentValue);
this.render();
}
}

@HostListener('window:scroll', ['$event'])
handleScroll(event) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/presentation/mobile/mobile.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core';
import * as mdData from 'raw-loader!../../../assets/docs/mobile-andorid.md';
import * as mdData from 'raw-loader!../../../assets/docs/think-tank/mobile-android.md';

@Component({
selector: 'app-mobile',
Expand Down
4 changes: 3 additions & 1 deletion src/app/presentation/think-tank/think-tank.component.html
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<component-markdown-render [data]="data" showToc="true"></component-markdown-render>
<div *ngIf="content">
<component-markdown-render [data]="content" showToc="true"></component-markdown-render>
</div>
49 changes: 44 additions & 5 deletions src/app/presentation/think-tank/think-tank.component.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,57 @@
import { Component, OnInit } from '@angular/core';
import * as mdData from 'raw-loader!../../../assets/docs/think-tank/qa.md';
import { Title } from '@angular/platform-browser';
import { ActivatedRoute } from '@angular/router';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Thinktanks, thinktanks } from './thinktanks';

@Component({
selector: 'app-think-tank',
templateUrl: './think-tank.component.html',
styleUrls: ['./think-tank.component.scss'],
})
export class ThinkTankComponent implements OnInit {
data = mdData.default;
currentSource: string;
src: string;
content: string;
tanks: Thinktanks = thinktanks;

constructor(title: Title) {
title.setTitle('Ledge DevOps 知识平台 - 智库');
constructor(
private title: Title,
private activatedRoute: ActivatedRoute,
private http: HttpClient
) {}

ngOnInit(): void {
this.activatedRoute.paramMap.subscribe((p) => {
const param = p.get('tank');
const currentCase = this.tanks.find((ca) => ca.source === param);
this.title.setTitle(
`${currentCase.displayName} DevOps 案例学习(互联网公司/传统公司) - Ledge DevOps 知识平台`
);
this.configSource(param);
});
}

private configSource(value: string) {
this.getCase(value);
}

ngOnInit(): void {}
async getCase(source: string) {
this.src = this.buildSrc(source);
this.currentSource = source;

const headers = new HttpHeaders().set(
'Content-Type',
'text/plain; charset=utf-8'
);
this.http
.get(this.src, { headers, responseType: 'text' })
.subscribe((response) => {
this.content = response;
});
}

private buildSrc(source: string) {
return `assets/docs/think-tank/${source}.md`;
}
}
2 changes: 2 additions & 0 deletions src/app/presentation/think-tank/think-tank.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { CustomMaterialModule } from '../../shared/custom-material.module';
import { SharedModule } from '../../shared/shared.module';
import { RouterModule } from '@angular/router';
import { ThinkTankComponent } from './think-tank.component';
import { HttpClientModule } from '@angular/common/http';

@NgModule({
declarations: [ThinkTankComponent],
imports: [
CommonModule,
HttpClientModule,
CustomMaterialModule,
SharedModule,
RouterModule.forChild([
Expand Down
13 changes: 13 additions & 0 deletions src/app/presentation/think-tank/thinktanks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export interface Thinktank {
displayName: string;
source: string;
default?: boolean;
}

export type Thinktanks = Array<Thinktank>;

// todo: 优先级根据内容的质量重新排序。现在的是后来的在后面 + 内容多的在前面,随机组合
export const thinktanks: Thinktanks = [
{ displayName: 'QA', source: 'qa', default: true },
{ displayName: 'Android', source: 'mobile-android', default: true },
];
2 changes: 1 addition & 1 deletion src/assets/docs/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
```checklist
- [ ] Eating
- [ ] Today
- [ ] breakfast
- [x] breakfast
- [ ] brunch
- [ ] elevenses
- [ ] lunch
Expand Down
File renamed without changes.

0 comments on commit f6ccb2f

Please sign in to comment.