Skip to content

Commit

Permalink
feat: add dialog for homeclick && fixed #6
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Apr 2, 2020
1 parent b650d87 commit 6532c52
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 42 deletions.
3 changes: 3 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { MobileComponent } from './presentation/mobile/mobile.component';
import { LedgeHelperComponent } from './presentation/ledge-helper/ledge-helper.component';
import { ThinkTankComponent } from './presentation/think-tank/think-tank.component';
import { SolutionComponent } from './presentation/solution/solution.component';
import { AtomDialogComponent } from './features/atom-dialog/atom-dialog.component';

@NgModule({
declarations: [
Expand All @@ -38,8 +39,10 @@ import { SolutionComponent } from './presentation/solution/solution.component';
PeriodicTableComponent,
AtomComponent,
AtomDetailsComponent,
AtomDialogComponent,
AppPhaseComponent,
AppWikiComponent,

CaseStudyComponent,
PatternComponent,
DesignComponent,
Expand Down
5 changes: 5 additions & 0 deletions src/app/features/atom-dialog/atom-dialog.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h2 mat-dialog-title>{{data.name}}</h2>
<mat-dialog-content class="mat-typography">
<p *ngIf="data.homepage">首页:<a href="{{data.homepage}}" target="_blank">{{data.homepage}}</a></p>
{{data.description}}
</mat-dialog-content>
Empty file.
26 changes: 26 additions & 0 deletions src/app/features/atom-dialog/atom-dialog.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { AtomDialogComponent } from './atom-dialog.component';
import { SharedModule } from '../../shared/shared.module';

describe('AtomDialogComponent', () => {
let component: AtomDialogComponent;
let fixture: ComponentFixture<AtomDialogComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [SharedModule],
declarations: [AtomDialogComponent],
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(AtomDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
16 changes: 16 additions & 0 deletions src/app/features/atom-dialog/atom-dialog.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Component, Inject, OnInit } from '@angular/core';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import { Atom } from '../shared';

@Component({
selector: 'app-atom-dialog',
templateUrl: './atom-dialog.component.html',
styleUrls: ['./atom-dialog.component.scss'],
})
export class AtomDialogComponent implements OnInit {
constructor(@Inject(MAT_DIALOG_DATA) public data: Atom) {
console.log(this.data);
}

ngOnInit(): void {}
}
1 change: 1 addition & 0 deletions src/app/features/atom/atom.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div class="atom-container {{ data.category }}"
[ngClass]="selectedCategory === data.category ? 'selected-category': 'unselect'"
(click)="clickAtom()"
(mouseenter)="debounceMouseEnter()"
(mouseleave)="debounceMouseLeave()">

Expand Down
39 changes: 25 additions & 14 deletions src/app/features/atom/atom.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
import { Subject } from 'rxjs';
import { debounceTime, takeUntil } from 'rxjs/operators';
import { HighlightState } from '../shared';
import { MatDialog } from '@angular/material/dialog';
import { AtomDialogComponent } from '../atom-dialog/atom-dialog.component';

// in milliseconds
const STAY_AT_LEAST = 250;
Expand Down Expand Up @@ -41,7 +43,7 @@ export class AtomComponent implements OnInit, OnChanges, OnDestroy {
mouseLeaveSubject = new Subject<number>();
private unsubscribe$ = new Subject<void>();

constructor() {
constructor(public dialog: MatDialog) {
this.backgroundStyles = {
blurry: false,
'solid-selected': false,
Expand All @@ -54,23 +56,21 @@ export class AtomComponent implements OnInit, OnChanges, OnDestroy {

ngOnInit() {
this.mouseEnterSubject
.pipe(
debounceTime(STAY_AT_LEAST),
takeUntil(this.unsubscribe$)
)
.subscribe((value: number) => this.hoverAtom.emit(value), err => console.error(err));
.pipe(debounceTime(STAY_AT_LEAST), takeUntil(this.unsubscribe$))
.subscribe(
(value: number) => this.hoverAtom.emit(value),
(err) => console.error(err)
);

this.mouseLeaveSubject
.pipe(
debounceTime(STAY_AT_LEAST),
takeUntil(this.unsubscribe$)
)
.subscribe(() => this.hoverAtom.emit(null), err => console.error(err));
.pipe(debounceTime(STAY_AT_LEAST), takeUntil(this.unsubscribe$))
.subscribe(
() => this.hoverAtom.emit(null),
(err) => console.error(err)
);
}

ngOnChanges(changes: SimpleChanges) {

}
ngOnChanges(changes: SimpleChanges) {}

ngOnDestroy() {
if (this.unsubscribe$) {
Expand All @@ -86,4 +86,15 @@ export class AtomComponent implements OnInit, OnChanges, OnDestroy {
debounceMouseLeave() {
this.mouseLeaveSubject.next(this.data.number);
}

clickAtom() {
const dialogRef = this.dialog.open(AtomDialogComponent, {
width: '250px',
data: this.data,
});

dialogRef.afterClosed().subscribe((result) => {
// console.log('The dialog was closed');
});
}
}
34 changes: 16 additions & 18 deletions src/app/features/shared/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
export interface HighlightState {
alkali: boolean;
alkaline: boolean;
lant: boolean;
actinoid: boolean;
transition: boolean;
postTransition: boolean;
metalloid: boolean;
nonMetal: boolean;
nobleGas: boolean;
alkali: boolean;
alkaline: boolean;
lant: boolean;
actinoid: boolean;
transition: boolean;
postTransition: boolean;
metalloid: boolean;
nonMetal: boolean;
nobleGas: boolean;
}

export interface Atom {
number: number;
category: string;
symbol: string;
name: string;
atomic_mass: number;
phase: string;
xpos: number;
ypos: number;
blurry: boolean;
name: string;
homepage: string;
description: string;
category: string;
number: number;
symbol: string;
pd: string;
}
20 changes: 10 additions & 10 deletions src/app/shared/custom-material.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { NgModule } from '@angular/core';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatButtonModule } from '@angular/material/button';
import { MatMenuModule } from '@angular/material/menu';
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner';
import {MatSliderModule} from '@angular/material/slider';
import {MatSidenavModule} from '@angular/material/sidenav';
import {MatIconModule} from '@angular/material/icon';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { MatSliderModule } from '@angular/material/slider';
import { MatSidenavModule } from '@angular/material/sidenav';
import { MatIconModule } from '@angular/material/icon';
import { MatDialogModule } from '@angular/material/dialog';

const modules = [
MatToolbarModule,
Expand All @@ -14,16 +15,15 @@ const modules = [
MatProgressSpinnerModule,
MatSliderModule,
MatSidenavModule,
MatIconModule
MatIconModule,
MatDialogModule,
];

@NgModule({
imports: modules,
declarations: [],
providers: [
],
providers: [],
exports: modules,
entryComponents: []
entryComponents: [],
})
export class CustomMaterialModule {
}
export class CustomMaterialModule {}
1 change: 1 addition & 0 deletions src/assets/periodic-table.json
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,7 @@
{
"name": "Coding DevOps",
"description": "CODING DevOps 提供从需求提交到产品迭代,从代码管理到持续集成,制品管理直至最终持续部署的全套流程。流水线标准化作业,自动化版本记录,降低企业研发管理难度,提升研发效率。",
"homepage": "https://coding.net/",
"category": "platform",
"number": 116,
"pay": "Pd",
Expand Down

0 comments on commit 6532c52

Please sign in to comment.