Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: TTL-910 add project dropdown
  • Loading branch information
mmaquina committed Jul 29, 2023
commit 13399b96852f460316d9d6bcceb13685da92c7d1
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ import { TimeRangeOptionsComponent } from './modules/reports/components/time-ran
import { V2RedirectComponent } from './modules/v2-redirect/v2-redirect.component';
import { SpinnerOverlayComponent } from './modules/shared/components/spinner-overlay/spinner-overlay.component';
import { SpinnerInterceptor } from './modules/shared/interceptors/spinner.interceptor';
import { SearchProjectComponent } from './modules/shared/components/search-project/search-project.component';

const maskConfig: Partial<IConfig> = {
validation: false,
Expand Down Expand Up @@ -142,6 +143,7 @@ const maskConfig: Partial<IConfig> = {
SubstractDatePipeDisplayAsFloat,
TechnologiesComponent,
SearchUserComponent,
SearchProjectComponent,
TimeEntriesSummaryComponent,
TimeDetailsPipe,
InputLabelComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="row scroll-table mt-5 ml-0">
<app-search-user [users]="users" (selectedUserId)="user($event)"></app-search-user>

<app-search-project [projects]="listProjects" (selectedProjectId)="project($event)"></app-search-project>
<table
class="table table-striped mb-0"
datatable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import { DataTableDirective } from 'angular-datatables';
import * as moment from 'moment';
import { Observable, Subject, Subscription } from 'rxjs';
import { filter } from 'rxjs/operators';
import { Entry } from 'src/app/modules/shared/models';
import { Entry, Project } from 'src/app/modules/shared/models';
import { DataSource } from 'src/app/modules/shared/models/data-source.model';
import { EntryState } from '../../../time-clock/store/entry.reducer';
import { getReportDataSource, getResultSumEntriesSelected } from '../../../time-clock/store/entry.selectors';
import { TotalHours } from '../../models/total-hours-report';
import { User } from 'src/app/modules/users/models/users';
import { LoadUsers, UserActionTypes } from 'src/app/modules/users/store/user.actions';
import { ParseDateTimeOffset } from '../../../shared/formatters/parse-date-time-offset/parse-date-time-offset';
import { LoadProjects, ProjectActionTypes } from 'src/app/modules/customer-management/components/projects/components/store/project.actions';

@Component({
selector: 'app-time-entries-table',
Expand All @@ -21,11 +22,13 @@ import { ParseDateTimeOffset } from '../../../shared/formatters/parse-date-time-
})
export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewInit {
@Output() selectedUserId = new EventEmitter<string>();
@Output() selectedProjectId = new EventEmitter<string>();

selectOptionValues = [15, 30, 50, 100, -1];
selectOptionNames = [15, 30, 50, 100, 'All'];
totalTimeSelected: moment.Duration;
users: User[] = [];
projects: Project[] = [];
removeFirstColumn = 'th:not(:first)';

dtOptions: any = {
Expand Down Expand Up @@ -82,9 +85,13 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
resultSumEntriesSelected$: Observable<TotalHours>;
totalHoursSubscription: Subscription;
dateTimeOffset: ParseDateTimeOffset;
listProjects: Project[] = [];


constructor(private store: Store<EntryState>, private actionsSubject$: ActionsSubject, private storeUser: Store<User> ) {
constructor(private store: Store<EntryState>,
private actionsSubject$: ActionsSubject,
private storeUser: Store<User>,
private storeProject: Store<Project>
) {
this.reportDataSource$ = this.store.pipe(select(getReportDataSource));
this.resultSumEntriesSelected$ = this.store.pipe(select(getResultSumEntriesSelected));
this.dateTimeOffset = new ParseDateTimeOffset();
Expand All @@ -102,6 +109,23 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
});
}

uploadProjects(): void {
this.storeProject.dispatch(new LoadProjects());
this.actionsSubject$
.pipe(filter((action: any) => action.type === ProjectActionTypes.LOAD_PROJECTS_SUCCESS))
.subscribe((action) => {
const sortProjects = [...action.payload];
sortProjects.sort((a, b) => a.name.localeCompare(b.name));
this.projects = sortProjects;
this.projects = this.projects.filter(project => project.status === 'active');
this.projects.forEach((project) => {
const projectWithSearchField = { ...project };
projectWithSearchField.search_field = `${project.customer.name} - ${project.name}`;
this.listProjects.push(projectWithSearchField);
});
});
}

ngOnInit(): void {
this.rerenderTableSubscription = this.reportDataSource$.subscribe((ds) => {
this.totalHoursSubscription = this.resultSumEntriesSelected$.subscribe((actTotalHours) => {
Expand All @@ -112,6 +136,7 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
this.rerenderDataTable();
});
this.uploadUsers();
this.uploadProjects();
}

ngAfterViewInit(): void {
Expand Down Expand Up @@ -172,6 +197,10 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
this.selectedUserId.emit(userId);
}

project(projectId: string) {
this.selectedProjectId.emit(projectId);
}

sumHoursEntriesSelected(entry: Entry, checked: boolean){
this.resultSumEntriesSelected = new TotalHours();
const duration = moment.duration(moment(entry.end_date).diff(moment(entry.start_date)));
Expand Down
8 changes: 8 additions & 0 deletions src/app/modules/reports/pages/reports.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ import { Component } from '@angular/core';
export class ReportsComponent {

userId: string;
projectId: string;
activityId: string;

user(userId: string){
this.userId = userId;
}
activity(activityId: string){
this.activityId = activityId;
}
project(projectId: string){
this.projectId = projectId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="form-group" >
<label>Projects: </label>

<ng-select [(ngModel)]="selectedProject" [multiple]="false" placeholder="Select project" (change)="updateProject()" class="selectProject">
<ng-option *ngFor="let project of projects" value={{project.id}}> <strong>{{project.customer.name}}</strong> - {{project.name}}</ng-option >
</ng-select>

</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
label {
width: 225px;
}
.selectProject {
display: inline-block;
width: 350px;
padding: 0 12px 15px 12px;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Component, EventEmitter, Input, Output } from '@angular/core';

@Component({
selector: 'app-search-project',
templateUrl: './search-project.component.html',
styleUrls: ['./search-project.component.scss'],
})

export class SearchProjectComponent {

readonly ALLOW_SELECT_MULTIPLE = false;
selectedProject: string[];

@Input() projects: string[] = [];

@Output() selectedProjectId = new EventEmitter<string[] | string>();

updateProject() {
this.selectedProjectId.emit(this.selectedProject.length === 0 ? '*' : this.selectedProject);
}
}