Skip to content

Commit

Permalink
Merge pull request #354 from sancsoft/349-add-show-current-only-filte…
Browse files Browse the repository at this point in the history
…r-to-project-list

Show Current Only
  • Loading branch information
rmaffitsancsoft authored Oct 24, 2024
2 parents 56c8bf1 + 03b2c63 commit 82fb520
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,19 @@
}
</hq-select-input>
}
@if(clientDetailService.showCurrentOnly$ | async){
<div class="inline-flex items-center">
<div class="text-[12px] mr-[10px] leading-none text-nowrap">
Show current only
</div>
<label class="relative inline-flex cursor-pointer items-center">
<input id="switch" type="checkbox" class="peer sr-only" [formControl]="clientDetailService.currentOnly" checked />
<label for="switch" class="hidden"></label>
<div
class="peer h-[14px] w-[33px] rounded-full bg-slate-200 after:absolute after:left-[4px] after:top-[3px] after:h-[8px] after:w-[8px] after:rounded-full after:bg-gray-500 peer-checked:after:bg-white after:transition-all after:content-[''] peer-checked:bg-steel-blue-600 peer-checked:after:translate-x-full peer-checked:after:right-[12px] peer-checked:after:left-auto">
</div>
</label>
<div class="text-xs ml-[6px]">On</div>
</div>
}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<div class="flex flex-col xl:flex-row justify-between items-start gap-4">
<hq-client-details-search-filter></hq-client-details-search-filter>
<div class="flex divide-x ml-auto">
<hq-tab routerLink="projects">Projects</hq-tab>
<hq-tab routerLink="quotes">Quotes</hq-tab>
<hq-tab routerLink="projects" (click)="clientDetailsService.showCurrentOnly()">Projects</hq-tab>
<hq-tab routerLink="quotes" (click)="clientDetailsService.hideCurrentOnly()">Quotes</hq-tab>
<!-- <hq-tab routerLink="services">Services</hq-tab>
<hq-tab routerLink="invoices">Invoices</hq-tab> -->
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class ClientDetailsComponent {
private subscriptions: Subscription[] = [];

constructor(
private clientDetailsService: ClientDetailsService,
public clientDetailsService: ClientDetailsService,
private route: ActivatedRoute,
) {
const clientId$ = route.paramMap.pipe(map((t) => t.get('clientId')));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,25 @@ import { GetClientInvoiceSummaryV1Response } from '../../models/clients/get-clie
})
export class ClientDetailsService {
ProjectStatus = ProjectStatus;
currentOnly = new FormControl<boolean>(true);

search = new FormControl<string | null>(null);
projectStatus = new FormControl<ProjectStatus | null>(null);

showProjectStatus$: Observable<boolean>;
showCurrentOnly$: Observable<boolean>;

clientId$: Observable<string>;
client$: Observable<GetClientRecordV1>;
clientInvoiceSummary$: Observable<GetClientInvoiceSummaryV1Response>;

private showCurrentOnlySubject = new BehaviorSubject<boolean>(true);
private showProjectStatusSubject = new BehaviorSubject<boolean>(true);
private clientIdSubject = new BehaviorSubject<string | null>(null);

constructor(private hqService: HQService) {
this.showProjectStatus$ = this.showProjectStatusSubject.asObservable();
this.showCurrentOnly$ = this.showCurrentOnlySubject.asObservable();

this.clientId$ = this.clientIdSubject.asObservable().pipe(
filter((clientId) => clientId != null),
Expand Down Expand Up @@ -71,4 +75,11 @@ export class ClientDetailsService {
this.clientIdSubject.next(clientId);
}
}
showCurrentOnly(){
this.showCurrentOnlySubject.next(true);
}
hideCurrentOnly(){
this.showCurrentOnlySubject.next(false);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
shareReplay,
combineLatest,
debounceTime,
switchMap,
switchMap,startWith
} from 'rxjs';
import { formControlChanges } from '../../../core/functions/form-control-changes';
import { BaseListService } from '../../../core/services/base-list.service';
Expand Down Expand Up @@ -43,9 +43,21 @@ export class ClientProjectListService extends BaseListService<
this.clientDetailsService.projectStatus,
).pipe(
tap(() => this.goToPage(1)),
tap((status)=> {
if(status != null){
this.clientDetailsService.currentOnly.setValue(false);
}
}),
shareReplay({ bufferSize: 1, refCount: false }),
);

const currentOnly$ = formControlChanges(this.clientDetailsService.currentOnly).pipe(
startWith(this.clientDetailsService.currentOnly.value),
tap(value => {
if (value){
this.clientDetailsService.projectStatus.setValue(null);
}
})
);
const result$ = combineLatest({
search: search$,
clientId: this.clientDetailsService.clientId$,
Expand All @@ -54,6 +66,7 @@ export class ClientProjectListService extends BaseListService<
sortBy: this.sortOption$,
projectStatus: projectStatus$,
sortDirection: this.sortDirection$,
currentOnly: currentOnly$
}).pipe(
debounceTime(500),
tap(() => this.loadingSubject.next(true)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ <h1 class="font-rajdhani font-semibold text-3xl">Projects</h1>
}
</hq-select-input>
</div>
@if(listService){}
<div class="inline-flex items-center">
<div class="text-[12px] mr-[10px] leading-none text-nowrap">
Show current only
</div>
<label class="relative inline-flex cursor-pointer items-center">
<input id="switch" type="checkbox" class="peer sr-only" [formControl]="listService.currentOnly" checked />
<label for="switch" class="hidden"></label>
<div
class="peer h-[14px] w-[33px] rounded-full bg-slate-200 after:absolute after:left-[4px] after:top-[3px] after:h-[8px] after:w-[8px] after:rounded-full after:bg-gray-500 peer-checked:after:bg-white after:transition-all after:content-[''] peer-checked:bg-steel-blue-600 peer-checked:after:translate-x-full peer-checked:after:right-[12px] peer-checked:after:left-auto">
</div>
</label>
<div class="text-xs ml-[6px]">On</div>
</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
Observable,
shareReplay,
switchMap,
tap,
tap, startWith
} from 'rxjs';
import { SortDirection } from '../../models/common/sort-direction';
import { HQService } from '../../services/hq.service';
Expand Down Expand Up @@ -43,6 +43,11 @@ export class ProjectListService extends BaseListService<
public projectStatus = new FormControl<ProjectStatus | null>(null);
public projectStatus$ = formControlChanges(this.projectStatus).pipe(
tap(() => this.goToPage(1)),
tap((status)=> {
if(status != null){
this.currentOnly.setValue(false);
}
}),
shareReplay({ bufferSize: 1, refCount: false }),
);

Expand All @@ -53,7 +58,15 @@ export class ProjectListService extends BaseListService<
);

projectManagers$: Observable<GetStaffV1Record[]>;

currentOnly = new FormControl<boolean>(true);
public currentOnly$ = formControlChanges(this.currentOnly).pipe(
startWith(this.currentOnly.value),
tap(value => {
if (value){
this.projectStatus.setValue(null);
}
})
);
protected override getResponse(): Observable<GetProjectResponseV1> {
return combineLatest({
search: this.search$,
Expand All @@ -63,6 +76,7 @@ export class ProjectListService extends BaseListService<
projectStatus: this.projectStatus$,
sortDirection: this.sortDirection$,
projectManagerId: this.projectManagerId$,
currentOnly: this.currentOnly$,
}).pipe(
debounceTime(500),
tap(() => this.loadingSubject.next(true)),
Expand Down
1 change: 1 addition & 0 deletions src/dotnet/HQ.Abstractions/Projects/GetProjectsV1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Request : PagedRequestV1
public SortColumn SortBy { get; set; } = SortColumn.ProjectName;
public SortDirection SortDirection { get; set; } = SortDirection.Asc;
public ProjectStatus? ProjectStatus { get; set; }
public bool? CurrentOnly { get; set; } = true;
}

public enum SortColumn
Expand Down
7 changes: 7 additions & 0 deletions src/dotnet/HQ.Server/Services/ProjectServiceV1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,13 @@ public ProjectServiceV1(ChargeCodeServiceV1 chargeCodeServiceV1, HQDbContext con
{
records = records.Where(t => t.Status == request.ProjectStatus);
}
if (request.CurrentOnly.HasValue)
{
if (request.CurrentOnly.Value)
{
records = records.Where(t => t.Status == ProjectStatus.InProduction || t.Status == ProjectStatus.Ongoing);
}
}
var bookingStartDate = DateOnly.FromDateTime(DateTime.Today).GetPeriodStartDate(Period.Month);
var bookingEndDate = DateOnly.FromDateTime(DateTime.Today).GetPeriodEndDate(Period.Month);

Expand Down

0 comments on commit 82fb520

Please sign in to comment.