Skip to content

Commit

Permalink
Refactor code and remove unused files
Browse files Browse the repository at this point in the history
  • Loading branch information
akozma89 committed Jan 5, 2024
1 parent 315e3f4 commit 84a9b75
Show file tree
Hide file tree
Showing 56 changed files with 261 additions and 227 deletions.
2 changes: 1 addition & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@if (loading$ | async) {
<div class="app-loader">
<div class="full-size-loader">
<nz-spin nzSimple nzSize="large"></nz-spin>
</div>
} @else {
Expand Down
7 changes: 0 additions & 7 deletions src/app/app.component.scss
Original file line number Diff line number Diff line change
@@ -1,7 +0,0 @@
.app-loader {
height: 100%;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
2 changes: 1 addition & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { EventNotificationsComponent } from './components/event-notifications/event-notifications.component';
import { Store } from '@ngrx/store';
import { AppStore } from './interfaces/app-store';
import { AppStore } from './interfaces/app-store.interface';
import { LoadMachinesAction } from './stores/machines/machines.actions';
import { LayoutComponent } from './components/layout/layout.component';
import { selectLoading } from '@stores/machines/machines.selectors';
Expand Down
6 changes: 3 additions & 3 deletions src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { provideRouter } from '@angular/router';
import { routes } from './app.routes';
import { provideStore } from '@ngrx/store';
import { machinesReducer } from './stores/machines/machines.reducer';
import { MACHINES_STORE } from './interfaces/machines-state';
import { MACHINES_STORE } from './interfaces/machines-state.interface';
import { provideStoreDevtools } from '@ngrx/store-devtools';
import { PLACES_STORE } from './interfaces/place-state';
import { PLACES_STORE } from './interfaces/place-state.interface';
import { placesReducer } from './stores/places/places.reducer';
import { provideEffects } from '@ngrx/effects';
import { MachinesEffects } from './stores/machines/machines.effects';
Expand All @@ -20,7 +20,7 @@ import { registerLocaleData } from '@angular/common';
import en from '@angular/common/locales/en';
import { FormsModule } from '@angular/forms';
import { provideAnimations } from '@angular/platform-browser/animations';
import { SETTINGS_STORE } from '@interfaces/settings-state';
import { SETTINGS_STORE } from '@interfaces/settings-state.interface';
import { settingsReducer } from '@stores/settings/settings.reducer';

registerLocaleData(en);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import {
} from '@angular/core';
import { NzNotificationModule } from 'ng-zorro-antd/notification';
import { NzNotificationService } from 'ng-zorro-antd/notification';
import { MachineColorStatusMap } from '../../interfaces/machine-events-options';
import { Subscription, bufferWhen, interval } from 'rxjs';
import { AppStore } from '@interfaces/app-store';
import { AppStore } from '@interfaces/app-store.interface';
import { Store } from '@ngrx/store';
import { selectSettingsFeature } from '@stores/settings/settings.selectors';
import { NotificationLevelSettings } from '@interfaces/settings-state';
import { NotificationLevelSettings } from '@interfaces/settings-state.interface';
import { NzTagModule } from 'ng-zorro-antd/tag';
import { MachineUpdateResponse } from '@interfaces/machine-update-response';
import { MachineUpdateResponse } from '@interfaces/machine-update-response.interface';
import { NzIconModule } from 'ng-zorro-antd/icon';
import { RouterLink } from '@angular/router';
import { NzGridModule } from 'ng-zorro-antd/grid';
import { environment } from '@environments/environment';
import { MACHINE_COLORS_STATUS_MAP } from '@constants/machine.constant';

@Component({
standalone: true,
Expand Down Expand Up @@ -91,11 +91,11 @@ export class EventNotificationsComponent implements OnInit, OnDestroy {
if (this.settings.notificationLevel[event.status]) {
this.notificationService.template(this.template!, {
nzData: {
color: MachineColorStatusMap[event.status],
color: MACHINE_COLORS_STATUS_MAP[event.status],
machine_id: event.machine_id,
status: event.status,
},
nzClass: MachineColorStatusMap[event.status],
nzClass: MACHINE_COLORS_STATUS_MAP[event.status],
nzPlacement: 'bottomRight',
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/map/map.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { MapComponent } from './map.component';
import { Place } from '@models/place';
import { Place } from '@models/place.model';

describe('MapComponent', () => {
let component: MapComponent;
Expand Down
7 changes: 3 additions & 4 deletions src/app/components/map/map.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
ViewChild,
} from '@angular/core';
import { environment } from '@environments/environment';
import { MachineCoordinate } from '@interfaces/place-state';
import { Machine } from '@models/machine';
import { Place } from '@models/place';
import { MachineCoordinate } from '@interfaces/place-state.interface';
import { Machine } from '@models/machine.model';
import { Place } from '@models/place.model';
import mapboxgl from 'mapbox-gl';
import { NgxResizeObserverModule } from 'ngx-resize-observer';
import { Subject, Subscription, debounceTime } from 'rxjs';
Expand Down Expand Up @@ -107,7 +107,6 @@ export class MapComponent
}

resizeMap(): void {
console.log('resize');
this.map.resize();
}
}
31 changes: 31 additions & 0 deletions src/app/constants/machine.constant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { StatusFilterOption } from '@interfaces/machine-events-options.interface';
import { NzTableFilterList } from 'ng-zorro-antd/table';

export enum MACHINE_STATUS_MAP {
idle = 'idle',
running = 'running',
errored = 'errored',
repaired = 'repaired',
finished = 'finished',
}

export const MACHINE_STATUS_FILTERS: StatusFilterOption[] = [
{ text: 'Idle', value: MACHINE_STATUS_MAP.idle },
{ text: 'Running', value: MACHINE_STATUS_MAP.running },
{ text: 'Errored', value: MACHINE_STATUS_MAP.errored },
{ text: 'Repaired', value: MACHINE_STATUS_MAP.repaired },
{ text: 'Finished', value: MACHINE_STATUS_MAP.finished },
];

export const MACHINE_COLORS_STATUS_MAP = {
[MACHINE_STATUS_MAP.idle]: 'info',
[MACHINE_STATUS_MAP.running]: 'warning',
[MACHINE_STATUS_MAP.errored]: 'error',
[MACHINE_STATUS_MAP.repaired]: 'success',
[MACHINE_STATUS_MAP.finished]: 'success',
};

export const MACHINE_TYPE_OPTIONS: NzTableFilterList = [
{ text: 'Microscope', value: 'microscope' },
{ text: 'Measurement', value: 'measurement' },
];
5 changes: 5 additions & 0 deletions src/app/interfaces/app-store.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { MachinesStore } from './machines-state.interface';
import { PlacesStore } from './place-state.interface';
import { SettingsStore } from './settings-state.interface';

export interface AppStore extends MachinesStore, PlacesStore, SettingsStore {}
5 changes: 0 additions & 5 deletions src/app/interfaces/app-store.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Machine } from '../models/machine';
import { Machine } from '../models/machine.model';

export interface Floor {
level: number;
Expand Down
12 changes: 12 additions & 0 deletions src/app/interfaces/machine-events-options.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export type MachineStatus = 'idle' | 'running' | 'errored' | 'repaired';

export interface StatusFilterOption {
text: string;
value: string;
byDefault?: boolean;
}

export interface MachineEventsOptions {
timestamp: string;
status: MachineStatus;
}
36 changes: 0 additions & 36 deletions src/app/interfaces/machine-events-options.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MachineEventsOptions, MachineStatus } from './machine-events-options';
import { MachineEventsOptions, MachineStatus } from './machine-events-options.interface';

export interface MachineOptions {
id: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MachineOptions } from './machine-options';
import { MachineOptions } from './machine-options.interface';

export interface MachineResponse {
data: MachineOptions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MachineEventsOptions } from './machine-events-options';
import { MachineEventsOptions } from './machine-events-options.interface';

export interface MachineUpdateResponse extends MachineEventsOptions {
machine_id: string;
Expand Down
7 changes: 7 additions & 0 deletions src/app/interfaces/machine.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { NzSafeAny } from 'ng-zorro-antd/core/types';

export interface MachineTypeOption {
text: string;
value: NzSafeAny;
byDefault?: boolean;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MachineOptions } from './machine-options';
import { MachineOptions } from './machine-options.interface';

export interface MachinesResponse {
data: MachineOptions[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EntityState } from '@ngrx/entity';
import { Machine } from '../models/machine';
import { Machine } from '../models/machine.model';

export const MACHINES_STORE = 'machinesStore';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Floor } from './floor';
import { Floor } from './floor.interface';

export interface PlaceOptions {
longitude: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EntityState } from '@ngrx/entity';
import { Place } from '../models/place';
import { Machine } from '../models/machine';
import { Place } from '../models/place.model';
import { Machine } from '../models/machine.model';

export const PLACES_STORE = 'placesStore';

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
MachineEventsOptions,
MachineStatus,
} from '../interfaces/machine-events-options';
} from '../interfaces/machine-events-options.interface';

export class MachineEvent {
timestamp: string;
Expand Down
4 changes: 2 additions & 2 deletions src/app/models/machine.ts → src/app/models/machine.model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MachineOptions } from '../interfaces/machine-options';
import { MachineEvent } from './machine-event';
import { MachineOptions } from '../interfaces/machine-options.interface';
import { MachineEvent } from './machine-event.model';

export class Machine {
id!: string;
Expand Down
27 changes: 27 additions & 0 deletions src/app/models/place.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { PlaceOptions } from '../interfaces/place-options.interface';
import { Machine } from './machine.model';
import { v4 as uuidv4 } from 'uuid';

export class Place {
id = uuidv4();
longitude!: number;
latitude!: number;
floors: PlaceOptions['floors'] = [];

constructor(options: PlaceOptions) {
this.longitude = options.longitude;
this.latitude = options.latitude;
this.floors = options.floors || [];
}

addMachine(machine: Machine) {
if (this.floors && this.floors[machine.floor]) {
this.floors[machine.floor].machines.push(machine.id);
} else if (this.floors) {
this.floors[machine.floor] = {
level: machine.floor,
machines: [machine.id],
};
}
}
}
66 changes: 0 additions & 66 deletions src/app/models/place.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';

import { DashboardPageComponent } from './dashboard-page.component';
import { MockStore, provideMockStore } from '@ngrx/store/testing';
import { AppStore } from '@interfaces/app-store';
import { AppStore } from '@interfaces/app-store.interface';
import { Store } from '@ngrx/store';

describe('DashboardPageComponent', () => {
Expand Down
Loading

0 comments on commit 84a9b75

Please sign in to comment.