Skip to content

Commit

Permalink
added project-card component + translations
Browse files Browse the repository at this point in the history
  • Loading branch information
geneacs committed Sep 3, 2019
1 parent 9772b63 commit bbbfb42
Show file tree
Hide file tree
Showing 14 changed files with 240 additions and 13 deletions.
2 changes: 2 additions & 0 deletions build-locale.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
src/locale/main/*.en-US.xlf \
src/locale/widgets/*.en-US.xlf \
src/locale/dashboard/*.en-US.xlf \
src/locale/projects/*.en-US.xlf \
-o src/locale/translations.en-US.xlf

./node_modules/xlf-merge/index.js \
src/locale/main/*.it-IT.xlf \
src/locale/widgets/*.it-IT.xlf \
src/locale/dashboard/*.it-IT.xlf \
src/locale/projects/*.it-IT.xlf \
-o src/locale/translations.it-IT.xlf
36 changes: 36 additions & 0 deletions src/app/pages/projects/project-card/project-card.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<mat-card class="md-padding"
class="d-flex flex-row align-items-stretch"
[class.mat-elevation-z2]="!isActive"
[class.mat-elevation-z8]="isActive"
(mouseover)="setActive(true)"
(mouseout)="setActive(false)">

<!-- Cover -->
<div *ngIf="!isActive" class="flex-fill d-flex align-items-end">
<h3>{{ project.name }}</h3>
</div>

<!-- Summary -->
<div *ngIf="isActive" class="flex-fill d-flex flex-column">
<header>
<h3>{{ project.name }}</h3>
</header>
<main class="flex-grow-1 d-flex flex-column">
<p class="multiline-ellipsis">{{ project.description }}</p>
<div class="m-1 d-flex flex-row align-items-center">
<mat-icon>devices_other</mat-icon>
<strong class="px-2">{{ deviceCount }}</strong>
<span i18n="@@projectCard-string-device">HYT_string_device</span>
</div>
<div class="m-1 d-flex flex-row align-items-center">
<mat-icon>code</mat-icon>
<strong class="px-2">{{ rulesCount }}</strong>
<span i18n="@@projectCard-string-rule">HYT_string_rule</span>
</div>
</main>
<footer class="mt-auto d-flex">
<button mat-stroked-button class="flex-grow-1" i18n="@@projectCard-button-view">HYT_button_view</button>
</footer>
</div>

</mat-card>
25 changes: 25 additions & 0 deletions src/app/pages/projects/project-card/project-card.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
mat-card {
background: whitesmoke;
width: 200px;
height: 260px;
margin: 8px;
border-radius: 6px;
}
mat-card:hover {
background: white;
}
h3 {
margin: 0;
}
.multiline-ellipsis {
font-size: 80%;
max-width: 100%;
height: 60px;
margin: 8px auto;
display: block;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}
25 changes: 25 additions & 0 deletions src/app/pages/projects/project-card/project-card.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { ProjectCardComponent } from './project-card.component';

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

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ProjectCardComponent ]
})
.compileComponents();
}));

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

it('should create', () => {
expect(component).toBeTruthy();
});
});
41 changes: 41 additions & 0 deletions src/app/pages/projects/project-card/project-card.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Component, OnInit, Input } from '@angular/core';
import { HProject, HDevice, HdevicesService, RulesService, Rule } from '@hyperiot/core';

@Component({
selector: 'hyt-project-card',
templateUrl: './project-card.component.html',
styleUrls: ['./project-card.component.scss']
})
export class ProjectCardComponent implements OnInit {
@Input() project: HProject;
isActive = false;
deviceCount = 0;
rulesCount = 0;
activeTimeout;

constructor(
private hDeviceService: HdevicesService,
private ruleService: RulesService
) { }

ngOnInit() {
this.hDeviceService.findAllHDevice().subscribe((deviceList: HDevice[]) => {
deviceList.forEach((d: HDevice) => {
d.project && d.project.id === this.project.id && this.deviceCount++;
});
});
this.ruleService.findAllRule().subscribe((ruleList: Rule[]) => {
ruleList.forEach((r: Rule) => {
r.project && r.project.id === this.project.id && this.rulesCount++;
});
});
}

setActive(active) {
if (this.activeTimeout) {
clearTimeout(this.activeTimeout);
}
this.activeTimeout = setTimeout(() => this.isActive = active, 10);
}

}
15 changes: 11 additions & 4 deletions src/app/pages/projects/projects.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

<div [ngSwitch]="pageStatus">

<div *ngSwitchCase="0">
<div *ngSwitchCase="PageStatus.Loading">
loading
</div>

<div *ngSwitchCase="1">
<div *ngSwitchCase="PageStatus.Standard">
<table>
<tr>
<th><b>ID</b></th>
Expand All @@ -24,9 +24,16 @@
<td>{{proj.user.username}}</td>
</tr>
</table>

<h2>Projects List</h2>
<div class="d-flex flex-row justify-content-center">
<hyt-project-card *ngFor="let p of hProjects" [project]="p">
</hyt-project-card>
</div>

</div>

<div *ngSwitchCase="2">
<div *ngSwitchCase="PageStatus.New">
<div class="no-projects row">
<div class="col-md-12">
Non ci sono progetti. Devi aggiungerne uno.
Expand All @@ -40,7 +47,7 @@
</div>
</div>

<div *ngSwitchCase="-1">
<div *ngSwitchCase="PageStatus.Error">
Errore
</div>

Expand Down
13 changes: 7 additions & 6 deletions src/app/pages/projects/projects.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { Router } from '@angular/router';
import { PageStatus } from './models/pageStatus';
import { HProject, HprojectsService } from '@hyperiot/core';


@Component({
selector: 'hyt-projects',
templateUrl: './projects.component.html',
styleUrls: ['./projects.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class ProjectsComponent implements OnInit {

PageStatus = PageStatus;
pageStatus: PageStatus = PageStatus.Loading;

hProjects: HProject[] = [];
Expand All @@ -24,18 +25,18 @@ export class ProjectsComponent implements OnInit {
this.hProjectService.findAllHProject().subscribe(
res => {
this.hProjects = res;
this.hProjects = [];
this.pageStatus = (this.hProjects.length != 0) ? PageStatus.Standard : PageStatus.New;
this.pageStatus = (this.hProjects.length !== 0)
? PageStatus.Standard
: PageStatus.New;
},
err => {
console.log(err)
console.log(err);
this.pageStatus = PageStatus.Error;
}
)
);
}

addProject() {
this.router.navigate(['/project-wizard']);
}

}
10 changes: 9 additions & 1 deletion src/app/pages/projects/projects.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import { ProjectStepComponent } from './project-wizard/project-step/project-step
import { StatisticsStepComponent } from './project-wizard/statistics-step/statistics-step.component';
import { EnrichmentStepComponent } from './project-wizard/enrichment-step/enrichment-step.component';

import { MatIconModule } from '@angular/material/icon';
import { MatCardModule, MatButtonModule } from '@angular/material';

import { ProjectCardComponent } from './project-card/project-card.component';


@NgModule({
Expand All @@ -24,9 +28,13 @@ import { EnrichmentStepComponent } from './project-wizard/enrichment-step/enrich
PacketsStepComponent,
ProjectStepComponent,
StatisticsStepComponent,
EnrichmentStepComponent
EnrichmentStepComponent,
ProjectCardComponent
],
imports: [
MatIconModule,
MatButtonModule,
MatCardModule,
CommonModule,
HyperiotComponentsModule,
ReactiveFormsModule
Expand Down
28 changes: 28 additions & 0 deletions src/locale/projects/translations.en-US.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="ng2.template">
<body>
<trans-unit id="projectCard-string-device" datatype="html">
<source>HYT_string_device</source>
<target>Device{{ deviceCount > 1 ? 's' : '' }}</target>
<context-group purpose="location">
<context context-type="sourcefile">app/pages/projects/project-card/project-card.component.html</context>
</context-group>
</trans-unit>
<trans-unit id="projectCard-string-rule" datatype="html">
<source>HYT_string_rule</source>
<target>Rule{{ rulesCount > 1 ? 's' : '' }}</target>
<context-group purpose="location">
<context context-type="sourcefile">app/pages/projects/project-card/project-card.component.html</context>
</context-group>
</trans-unit>
<trans-unit id="projectCard-button-view" datatype="html">
<source>HYT_button_view</source>
<target>View</target>
<context-group purpose="location">
<context context-type="sourcefile">app/pages/projects/project-card/project-card.component.html</context>
</context-group>
</trans-unit>
</body>
</file>
</xliff>
28 changes: 28 additions & 0 deletions src/locale/projects/translations.it-IT.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="ng2.template">
<body>
<trans-unit id="projectCard-string-device" datatype="html">
<source>HYT_string_device</source>
<target>Dispositiv{{ deviceCount > 1 ? 'i' : 'o' }}</target>
<context-group purpose="location">
<context context-type="sourcefile">app/pages/projects/project-card/project-card.component.html</context>
</context-group>
</trans-unit>
<trans-unit id="projectCard-string-rule" datatype="html">
<source>HYT_string_rule</source>
<target>Regol{{ rulesCount > 1 ? 'e' : 'a' }}</target>
<context-group purpose="location">
<context context-type="sourcefile">app/pages/projects/project-card/project-card.component.html</context>
</context-group>
</trans-unit>
<trans-unit id="projectCard-button-view" datatype="html">
<source>HYT_button_view</source>
<target>Visualizza</target>
<context-group purpose="location">
<context context-type="sourcefile">app/pages/projects/project-card/project-card.component.html</context>
</context-group>
</trans-unit>
</body>
</file>
</xliff>
25 changes: 25 additions & 0 deletions src/locale/projects/translations.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="ng2.template">
<body>
<trans-unit id="projectCard-string-device" datatype="html">
<source>HYT_string_device</source>
<context-group purpose="location">
<context context-type="sourcefile">app/pages/projects/project-card/project-card.component.html</context>
</context-group>
</trans-unit>
<trans-unit id="projectCard-string-rule" datatype="html">
<source>HYT_string_rule</source>
<context-group purpose="location">
<context context-type="sourcefile">app/pages/projects/project-card/project-card.component.html</context>
</context-group>
</trans-unit>
<trans-unit id="projectCard-button-view" datatype="html">
<source>HYT_button_view</source>
<context-group purpose="location">
<context context-type="sourcefile">app/pages/projects/project-card/project-card.component.html</context>
</context-group>
</trans-unit>
</body>
</file>
</xliff>
2 changes: 1 addition & 1 deletion src/locale/translations.en-US.xlf

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/locale/translations.it-IT.xlf

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@import "../node_modules/bootstrap/scss/grid";
@import "../node_modules/bootstrap/scss/utilities/display";
@import "../node_modules/bootstrap/scss/utilities/flex";
@import "../node_modules/bootstrap/scss/utilities/spacing";

body {
background: transparent;
Expand Down

0 comments on commit bbbfb42

Please sign in to comment.