Skip to content

Commit 82f4785

Browse files
authored
Merge pull request #10 from ioet/manage-projects-frontEnd
Manage projects
2 parents 7442cd1 + 6915493 commit 82f4785

21 files changed

+433
-16
lines changed

angular.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@
2424
"src/assets"
2525
],
2626
"styles": [
27+
"./node_modules/bootstrap/dist/css/bootstrap.min.css",
2728
"src/styles.css"
28-
],
29-
"scripts": []
29+
],
30+
"scripts": [
31+
"./node_modules/jquery/dist/jquery.min.js",
32+
"./node_modules/bootstrap/dist/js/bootstrap.min.js"
33+
]
3034
},
3135
"configurations": {
3236
"production": {

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
"@angular/platform-browser": "~9.0.3",
2020
"@angular/platform-browser-dynamic": "~9.0.3",
2121
"@angular/router": "~9.0.3",
22+
"bootstrap": "^4.4.1",
23+
"jquery": "^3.4.1",
2224
"rxjs": "~6.5.4",
2325
"tslib": "^1.10.0",
2426
"zone.js": "~0.10.2"

src/app/app-routing.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ReportsComponent } from './components/options-sidebar/reports/reports.c
55
import { TimeClockComponent } from './components/options-sidebar/time-clock/time-clock.component';
66
import { TimeEntriesComponent } from './components/options-sidebar/time-entries/time-entries.component';
77
import { TimeOffComponent } from './components/options-sidebar/time-off/time-off.component';
8+
import { ProjectManagementComponent } from './components/options-sidebar/project-management/project-management.component';
89

910

1011
const routes: Routes = [
@@ -13,6 +14,7 @@ const routes: Routes = [
1314
{path: 'time-clock', component: TimeClockComponent},
1415
{path: 'time-entries', component: TimeEntriesComponent},
1516
{path: 'time-off', component: TimeOffComponent},
17+
{path: 'project-management', component: ProjectManagementComponent},
1618
{path: '', pathMatch: 'full', redirectTo: 'getting-started'},
1719
{path: '**', pathMatch: 'full', redirectTo: 'getting-started'},
1820
];

src/app/app.component.spec.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,4 @@ describe('AppComponent', () => {
2525
const app = fixture.componentInstance;
2626
expect(app.title).toEqual('time-tracker');
2727
});
28-
29-
it('should render title', () => {
30-
const fixture = TestBed.createComponent(AppComponent);
31-
fixture.detectChanges();
32-
const compiled = fixture.nativeElement;
33-
expect(compiled.querySelector('.content span').textContent).toContain('time-tracker app is running!');
34-
});
3528
});

src/app/app.module.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
11
import { BrowserModule } from '@angular/platform-browser';
22
import { NgModule } from '@angular/core';
3+
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
34

45
import { AppRoutingModule } from './app-routing.module';
56
import { AppComponent } from './app.component';
67
import { NavbarComponent } from './components/shared/navbar/navbar.component';
78
import { UserComponent } from './components/shared/user/user.component';
89
import { SidebarComponent } from './components/shared/sidebar/sidebar.component';
910
import { ClockComponent } from './components/shared/clock/clock.component';
10-
11+
import { ProjectManagementComponent } from './components/options-sidebar/project-management/project-management.component';
12+
import { ProjectListComponent } from './components/shared/project-list/project-list.component';
13+
import { CreateProjectComponent } from './components/shared/create-project/create-project.component';
1114
@NgModule({
1215
declarations: [
1316
AppComponent,
1417
NavbarComponent,
1518
UserComponent,
1619
SidebarComponent,
1720
ClockComponent,
21+
ProjectManagementComponent,
22+
ProjectListComponent,
23+
CreateProjectComponent
1824
],
1925
imports: [
2026
BrowserModule,
21-
AppRoutingModule
27+
AppRoutingModule,
28+
FormsModule,
29+
ReactiveFormsModule
2230
],
2331
providers: [],
2432
bootstrap: [AppComponent]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.parent {
2+
display: flex;
3+
}
4+
5+
.item {
6+
width: 50%;
7+
margin: 2em;
8+
min-height: 500px;
9+
max-height: 500px;
10+
}
11+
12+
@media screen and (max-width: 600px){
13+
.parent {
14+
flex-direction: column-reverse;
15+
}
16+
17+
.item {
18+
width: auto;
19+
min-height: 200px;
20+
}
21+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
<div class="parent">
3+
4+
<app-create-project class="item"
5+
[projectToEdit] = "project"
6+
(savedProject)="updateProject($event)"
7+
(cancelForm) = "cancelForm()"
8+
>
9+
</app-create-project>
10+
11+
<app-project-list class="item"
12+
[projects] = "projects"
13+
(editProject) = "editProject($event)"
14+
>
15+
</app-project-list>
16+
</div>
17+
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { ProjectManagementComponent } from './project-management.component';
4+
import { Project } from '../../../interfaces/project';
5+
6+
describe('ProjectManagementComponent', () => {
7+
let component: ProjectManagementComponent;
8+
let fixture: ComponentFixture<ProjectManagementComponent>;
9+
const projects: Project[] = [{
10+
id: 1,
11+
name: 'app 1',
12+
details: 'It is a good app',
13+
status: 'inactive',
14+
completed: true
15+
},
16+
{
17+
id: 2,
18+
name: 'app 2',
19+
details: 'It is a good app',
20+
status: 'inactive',
21+
completed: false
22+
},
23+
{
24+
id: 3,
25+
name: 'app 3',
26+
details: 'It is a good app',
27+
status: 'active',
28+
completed: true
29+
}
30+
];
31+
32+
beforeEach(async(() => {
33+
TestBed.configureTestingModule({
34+
declarations: [ ProjectManagementComponent ]
35+
})
36+
.compileComponents();
37+
}));
38+
39+
beforeEach(() => {
40+
fixture = TestBed.createComponent(ProjectManagementComponent);
41+
component = fixture.componentInstance;
42+
fixture.detectChanges();
43+
component.projects = projects;
44+
});
45+
46+
it('should create', () => {
47+
expect(component).toBeTruthy();
48+
});
49+
50+
it('should add a project #updateProject', () => {
51+
const project = {
52+
name: 'app 4',
53+
details: 'It is a good app',
54+
status: 'inactive',
55+
completed: true
56+
};
57+
58+
component.editedProjectId = null;
59+
component.updateProject(project);
60+
expect(component.projects.length).toEqual(4);
61+
});
62+
63+
it('should edit a project #updateProject', () => {
64+
const project = {
65+
id: 1,
66+
name: 'app test',
67+
details: 'It is a excelent app',
68+
status: 'inactive',
69+
completed: true
70+
};
71+
72+
component.editedProjectId = 1;
73+
component.updateProject(project);
74+
expect(component.projects.length).toEqual(3);
75+
expect(component.projects[0].name).toBe('app test');
76+
expect(component.projects[0].details).toBe('It is a excelent app');
77+
expect(component.projects[0].status).toBe('inactive');
78+
expect(component.projects[0].completed).toBe(true);
79+
});
80+
81+
it('should filter the project to edit #editProject', () => {
82+
const editProjectId = 2;
83+
component.editProject(editProjectId);
84+
expect(component.project.name).toBe('app 2');
85+
});
86+
87+
it('should clean the project #cancelForm', () => {
88+
const project = {
89+
id: 1,
90+
name: 'app 1',
91+
details: 'It is a good app',
92+
status: 'inactive',
93+
completed: true
94+
};
95+
96+
component.project = project;
97+
component.cancelForm();
98+
expect(component.project).toBe(null);
99+
});
100+
});
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import { Project } from '../../../interfaces/project';
3+
import { Input } from '@angular/core';
4+
import { Output, EventEmitter } from '@angular/core';
5+
@Component({
6+
selector: 'app-project-management',
7+
templateUrl: './project-management.component.html',
8+
styleUrls: ['./project-management.component.css']
9+
})
10+
export class ProjectManagementComponent implements OnInit {
11+
12+
editedProjectId;
13+
14+
project: Project;
15+
16+
projects: Project[] = [
17+
{ id: 1, name: 'GoSpace', details: 'Improve workspaces', status: 'Active', completed: false},
18+
{ id: 2, name: 'MidoPlay', details: 'Lottery', status: 'Inactive', completed: true}
19+
];
20+
21+
constructor() { }
22+
23+
ngOnInit(): void {
24+
}
25+
26+
updateProject(projectData): void {
27+
if (this.editedProjectId) {
28+
const projectIndex = this.projects.findIndex((project => project.id === this.editedProjectId));
29+
this.projects[projectIndex].name = projectData.name;
30+
this.projects[projectIndex].details = projectData.details;
31+
this.projects[projectIndex].status = projectData.status;
32+
this.projects[projectIndex].completed = projectData.completed;
33+
} else {
34+
const newProject: Project = { id: this.projects.length + 1, name: projectData.name,
35+
details: projectData.details, status: projectData.status, completed: false
36+
};
37+
this.projects = this.projects.concat(newProject);
38+
}
39+
console.log(this.projects);
40+
}
41+
42+
editProject(projectId) {
43+
this.editedProjectId = projectId;
44+
this.project = this.projects.filter((project) => project.id === projectId)[0];
45+
}
46+
47+
cancelForm() {
48+
this.project = null;
49+
}
50+
}

0 commit comments

Comments
 (0)