Skip to content

Commit

Permalink
feat: add building location
Browse files Browse the repository at this point in the history
  • Loading branch information
thongdanghoang committed Feb 16, 2025
1 parent 9cb00b4 commit c6cbd91
Show file tree
Hide file tree
Showing 17 changed files with 284 additions and 95 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package enterprise.dtos;

import green_buildings.commons.api.BaseDTO;
import jakarta.validation.constraints.DecimalMax;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import lombok.Builder;

Expand All @@ -11,6 +14,8 @@ public record BuildingDTO(
UUID id,
int version,
@NotBlank String name,
long numberOfDevices
@Min(0) long numberOfDevices,
@DecimalMin("-90.0") @DecimalMax("90.0") double latitude,
@DecimalMin("-180.0") @DecimalMax("180.0") double longitude
) implements BaseDTO {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.validation.constraints.DecimalMax;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
Expand All @@ -32,4 +34,14 @@ public class BuildingEntity extends AbstractAuditableEntity {
@Column(name = "number_of_devices", nullable = false)
private long numberOfDevices;

@DecimalMin("-90.0")
@DecimalMax("90.0")
@Column(name = "latitude")
private double latitude;

@DecimalMin("-180.0")
@DecimalMax("180.0")
@Column(name = "longitude")
private double longitude;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE buildings
ADD COLUMN latitude double precision NOT NULL;
ALTER TABLE buildings
ADD COLUMN longitude double precision NOT NULL;
23 changes: 23 additions & 0 deletions sep490-enterprise/src/main/resources/test-data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
INSERT INTO public.enterprises (created_date, created_by, last_modified_date, last_modified_by, id, version, hotline, name, email)
VALUES ('2025-02-16 20:36:14.312269', 'Anonymous', '2025-02-16 20:36:14.312269', 'Anonymous',
'f87565e6-e229-4e9b-b74d-4e085d05395e', 0, '0301930055', 'FPT University', 'fptu.hcm@fpt.edu.vn');
INSERT INTO public.buildings (created_date, created_by, last_modified_date, last_modified_by, id, version, enterprise_id, name,
number_of_devices, latitude, longitude)
VALUES ('2025-02-16 20:45:00.595269', 'fptu.hcm@fpt.edu.vn', '2025-02-16 20:45:00.595269', 'fptu.hcm@fpt.edu.vn',
'99c0932f-e8b1-44a3-a93a-514f992ef9cf', 0, 'f87565e6-e229-4e9b-b74d-4e085d05395e', 'FPT Quy Nhon', 500,
13.796696244798206, 109.21856202185155);
INSERT INTO public.buildings (created_date, created_by, last_modified_date, last_modified_by, id, version, enterprise_id, name,
number_of_devices, latitude, longitude)
VALUES ('2025-02-16 21:58:43.298707', 'fptu.hcm@fpt.edu.vn', '2025-02-16 21:58:43.298707', 'fptu.hcm@fpt.edu.vn',
'c746d31a-f132-4ceb-9c96-f14c5e629531', 0, 'f87565e6-e229-4e9b-b74d-4e085d05395e', 'FPT Can Tho', 123, 10.013038185016901,
105.7318063080311);
INSERT INTO public.buildings (created_date, created_by, last_modified_date, last_modified_by, id, version, enterprise_id, name,
number_of_devices, latitude, longitude)
VALUES ('2025-02-16 22:31:08.315223', 'fptu.hcm@fpt.edu.vn', '2025-02-16 22:31:08.315223', 'fptu.hcm@fpt.edu.vn',
'648af581-2635-4eed-9aee-b592085c16f3', 0, 'f87565e6-e229-4e9b-b74d-4e085d05395e', 'FPT Hà Nội', 123, 21.013579709497332,
105.52510991692544);
INSERT INTO public.buildings (created_date, created_by, last_modified_date, last_modified_by, id, version, enterprise_id, name,
number_of_devices, latitude, longitude)
VALUES ('2025-02-16 20:36:27.019184', 'fptu.hcm@fpt.edu.vn', '2025-02-16 20:36:27.019184', 'fptu.hcm@fpt.edu.vn',
'c8636202-c2ff-49e7-a43a-267a4dfa1658', 0, 'f87565e6-e229-4e9b-b74d-4e085d05395e', 'FPT Ho Chi Minh', 123,
10.84139877290165, 106.81006103754045);
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {AppRoutingConstants} from '../../../../app-routing.constant';
import {BuildingService} from '../../../../services/building.service';
import {AbstractFormComponent} from '../../../shared/components/form/abstract-form-component';
import {BuildingDetails} from '../../models/enterprise.dto';
import {MapLocation} from '../buildings/buildings.component';

@Component({
selector: 'app-building-detail',
Expand All @@ -31,7 +32,17 @@ export class BuildingDetailsComponent extends AbstractFormComponent<BuildingDeta
numberOfDevices: new FormControl(0, {
nonNullable: true,
validators: [Validators.min(1), Validators.required]
})
}),
latitude: new FormControl<number | null>(null, [
Validators.required,
Validators.min(-90),
Validators.max(90)
]),
longitude: new FormControl<number | null>(null, [
Validators.required,
Validators.min(-180),
Validators.max(180)
])
};

constructor(
Expand Down Expand Up @@ -75,6 +86,23 @@ export class BuildingDetailsComponent extends AbstractFormComponent<BuildingDeta
.subscribe(building => {
this.formGroup.patchValue(building);
});
this.activatedRoute.queryParams
.pipe(
takeUntil(this.destroy$),
filter((params): params is MapLocation => !!params)
)
.subscribe(location => {
if (!!location.latitude && !!location.longitude) {
this.buildingDetailsStructure.latitude.setValue(location.latitude);
this.buildingDetailsStructure.longitude.setValue(location.longitude);
} else if (!this.isEdit) {
this.notificationService.add({
severity: 'error',
summary: 'Error',
detail: 'Invalid location'
});
}
});
}

protected initializeFormControls(): {[p: string]: AbstractControl} {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div>
<span class="font-bold">
{{ "enterprise.buildings.details.labels.name" | translate }}:
</span>
{{ building.name }}
</div>
<div>
<span class="font-bold">
{{ "enterprise.buildings.details.labels.address" | translate }}:
</span>
{{ building.address }}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {Component, Input} from '@angular/core';
import {Building} from '../../models/enterprise.dto';

@Component({
selector: 'app-building-popup-marker',
templateUrl: './building-popup-marker.component.html',
styleUrl: './building-popup-marker.component.css'
})
export class BuildingPopupMarkerComponent {
@Input({required: true}) building!: Building;
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<div class="flex justify-between items-center">
<div class="flex justify-between items-center" style="min-height: 42px">
<div class="font-medium text-2xl">
{{ "enterprise.buildings.overview.title" | translate }}
</div>
<p-button
*ngIf="!addBuildingLocation"
severity="primary"
[label]="'enterprise.buildings.overview.btn.add' | translate"
icon="pi pi-building"
(onClick)="addBuilding()"
(onClick)="turnOnSelectBuildingLocation()"
/>
</div>

<p-selectbutton
(onChange)="onViewModeChanged($event)"
(onChange)="onViewModeChanged()"
[disabled]="addBuildingLocation"
[options]="justifyOptions"
[(ngModel)]="viewMode"
optionValue="value"
Expand All @@ -29,6 +31,26 @@
<div class="h-full" id="map"></div>
</div>

@if (mapView) {
<div class="flex justify-end gap-4">
<p-button
class="*:min-w-20"
*ngIf="addBuildingLocation"
severity="primary"
[label]="'common.cancel' | translate"
outlined
(onClick)="cancelAddBuilding()"
/>
<p-button
class="*:min-w-24"
*ngIf="addBuildingLocation"
severity="primary"
[label]="'common.next' | translate"
(onClick)="addBuilding()"
/>
</div>
}

@if (listView) {
@for (building of buildings; track building.id) {
<ng-container
Expand All @@ -47,7 +69,12 @@
icon="pi pi-info"
text
/>
<p-button icon="pi pi-map" text />
<p-button
icon="pi pi-map"
text
(onClick)="zoomTo(building.latitude, building.longitude)"
/>
<p-button icon="pi pi-trash" severity="warn" text />
</div>
</div>
<div class="p-4 border-b">
Expand Down
Loading

0 comments on commit c6cbd91

Please sign in to comment.