diff --git a/.travis.yml b/.travis.yml index da8c8084..39b09265 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,40 +47,40 @@ matrix: keep-history: true on: branch: master - # - language: android - # android: - # components: - # - tools - # notifications: - # email: false - # before_install: - # - yes | sdkmanager "platforms;android-26" - # install: - # - nvm install 9 - # - npm install - # - npm install -g cordova - # - echo y | android update sdk -u --filter android-22,android-23 - # - npm run build:mobile - # before_deploy: - # - git config --local user.name "TravisBuildAgent" - # - git config --local user.email "travis@travis-ci.org" - # - git tag "$(date +'%Y%m%d%H%M%S')-$(git log --format=%h -1)" - # deploy: - # provider: releases - # api_key: - # secure: hu/XAmiqTJDH+4rGGEgTZATXIlX/9RjYTq3wS2+1ltnmEqNmKuImCLpz4W+Gd2WLa4nE04zVZONSjVwLjx1eNKO/mM5TPMT4NL2zZsEGDkKXajBRe+WiyZafvVZTNfbmTxmPnOoQQW0I3IjNVPEltx6dwBny0423cqkQcR9ORxGgZNvL+Ic/AuHEahQmdZzP74gk2hWFNh75U4sN2O0vstWqH2c1EU3owk0NYaw/1QMfy0Mk5sI7/87tlae8AuZ6wqWIkCYuUQHnEDfyYva3Qj0vPnde4fLvf+MOiDZ1y+uuFP44LjjjFdMntOIeGq8SU+7OrwWyU7t/wbB8e+VXqjnjzxoWEIw0xWtRXi+sPpVcKJgyhayJu5+eJlj3LK22rMKtzRhLg2lTG1xOBL7YLHnanBFPAyZRVGtPH9YFEFcwuJvDLXoQQVuZWy+nOtAxvsBxKf4fPFGXVfnigRdtZrx/7yauVUVer1rJndxsRNrGhIBFrVzLiP5Xg701Lc1XDLk1XxCEEv7HOj0OEiP8jL+FZL0q3JXO2C2yE1X/fLJ3pPFLmHBqbMTNYkQs7LhtVmtN0aKcGosvRChVeFQjevkG23se2wxHuIbx3NMz9ipumzuHUt+TZQOaTn3TqxUmo1b7Uim5hKZKMq6CTGyPoOjHywQDo76gZxj6ZMpAtZ8= - # file: "$TRAVIS_BUILD_DIR/mobile/platforms/android/app/build/outputs/apk/release/app-release-unsigned.apk" - # on: - # repo: owsolutions/angular5-iot-dashboard - # skip_cleanup: true - # overwrite: true - # prerelease: true - # before_script: - # - cordova platform rm android - # - cordova platform add android - # script: - # - cd mobile - # - cordova prepare - # - cordova build android --release -- --ant - # release: - # - exit 0 + - language: android + android: + components: + - tools + notifications: + email: false + before_install: + - yes | sdkmanager "platforms;android-26" + install: + - nvm install 9 + - npm install + - npm install -g cordova + - echo y | android update sdk -u --filter android-22,android-23 + - npm run build:mobile + before_deploy: + - git config --local user.name "TravisBuildAgent" + - git config --local user.email "travis@travis-ci.org" + - git tag "$(date +'%Y%m%d%H%M%S')-$(git log --format=%h -1)" + deploy: + provider: releases + api_key: + secure: hu/XAmiqTJDH+4rGGEgTZATXIlX/9RjYTq3wS2+1ltnmEqNmKuImCLpz4W+Gd2WLa4nE04zVZONSjVwLjx1eNKO/mM5TPMT4NL2zZsEGDkKXajBRe+WiyZafvVZTNfbmTxmPnOoQQW0I3IjNVPEltx6dwBny0423cqkQcR9ORxGgZNvL+Ic/AuHEahQmdZzP74gk2hWFNh75U4sN2O0vstWqH2c1EU3owk0NYaw/1QMfy0Mk5sI7/87tlae8AuZ6wqWIkCYuUQHnEDfyYva3Qj0vPnde4fLvf+MOiDZ1y+uuFP44LjjjFdMntOIeGq8SU+7OrwWyU7t/wbB8e+VXqjnjzxoWEIw0xWtRXi+sPpVcKJgyhayJu5+eJlj3LK22rMKtzRhLg2lTG1xOBL7YLHnanBFPAyZRVGtPH9YFEFcwuJvDLXoQQVuZWy+nOtAxvsBxKf4fPFGXVfnigRdtZrx/7yauVUVer1rJndxsRNrGhIBFrVzLiP5Xg701Lc1XDLk1XxCEEv7HOj0OEiP8jL+FZL0q3JXO2C2yE1X/fLJ3pPFLmHBqbMTNYkQs7LhtVmtN0aKcGosvRChVeFQjevkG23se2wxHuIbx3NMz9ipumzuHUt+TZQOaTn3TqxUmo1b7Uim5hKZKMq6CTGyPoOjHywQDo76gZxj6ZMpAtZ8= + file: "$TRAVIS_BUILD_DIR/mobile/platforms/android/app/build/outputs/apk/release/app-release-unsigned.apk" + on: + repo: owsolutions/angular5-iot-dashboard + skip_cleanup: true + overwrite: true + prerelease: true + before_script: + - cordova platform rm android + - cordova platform add android + script: + - cd mobile + - cordova prepare + - cordova build android --release -- --ant + release: + - exit 0 diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 39c29d4d..734b3f9e 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -6,7 +6,6 @@ import { FormsModule } from '@angular/forms'; import { appReducersGenerator } from './app.reducers'; import { createRoutes } from './app.routes'; import { NgMediaModule } from './ng-media/ng-media-module'; -import { RealtimeService } from '@services/realtime.service'; import { NotificationService } from '@services/notification.service'; import { SettingsComponent } from '@components/settings/settings.component'; import { PageHeaderComponent } from '@components/page-header/page-header.component'; @@ -18,75 +17,37 @@ import { RequestsService } from '@services/requests.service'; import { CheckboxInputComponent } from '@components/forms/checkbox-input/checkbox-input.component'; import { ActionsService } from '@services/actions.service'; import { UserService, AuthGuard } from '@services/user.service'; -import { DevicesComponent } from '@components/devices/devices.component'; -import { ActivityWidgetComponent } from '@components/activity/activity-widget/activity-widget.component'; -import { LocationsComponent } from '@components/locations/locations.component'; -import { ActivityComponent } from '@components/activity/activity.component'; -import { LocationRowComponent } from '@components/locations/location-row/location-row.component'; -import { LocationSingleComponent } from '@components/locations/location-single/location-single.component'; import { OutputPinViewComponent } from '@components/output-pin-view/output-pin-view.component'; -import { SwitchWidgetsComponent } from '@components/switch-widgets/switch-widgets.component'; -import { IconWidgetsComponent } from '@components/index/icon-widgets/icon-widgets.component'; -import { PlacesComponent } from '@components/index/places/places.component'; -import { IndexComponent } from '@components/index/index.component'; import { UserWidgetComponent } from '@components/user-widget/user-widget.component'; import { GalleryComponent } from '@components/gallery/gallery.component'; import { LoadingComponent } from '@components/loading/loading.component'; import { NavigationComponent } from '@components/navigation/navigation.component'; import { SidebarWidgetComponent } from '@components/sidebar-widget/sidebar-widget.component'; import { IotSvgService } from '@services/iot-svg/iot-svg.service'; -import { DeviceSingleComponent } from 'app/components/device-single/device-single.component'; -import { DocsComponent } from '@components/docs/docs.component'; -import { DocsApiWorkaroundComponent } from '@components/docs/docs-api-workaround/docs-api-workaround.component'; -import { DeviceGeneralInformationComponent } from 'app/components/device-general-information/device-general-information.component'; -import { DeviceTemperatureComponent } from '@app/components/device-temperature/device-temperature.component'; -import { DeviceLampComponent } from '@app/components/device-lamp/device-lamp.component'; -import { DeviceCO2Component } from '@app/components/device-co2/device-co2.component'; -import { DeviceHumidityComponent } from '@app/components/device-humidity/device-humidity.component'; -import { StatisticsComponent } from '@components/statistics/statistics.component'; import { environment } from '../environments/environment'; import { HTTP_INTERCEPTORS } from '@angular/common/http'; import { MockInterceptor } from '@services/mock.interceptor'; import { MockService } from '@services/mocks.service'; import { TokenInterceptor } from '@services/token.interceptor'; import { GeneralInterceptorService } from '@services/general-interceptor.service'; -import { QuickChartComponent } from './components/quick-chart/quick-chart.component'; -import { ProgressLineComponent } from './components/progress-line/progress-line.component'; -import { RealtimeDocumentModule } from 'realtime-document'; +import { QuickChartComponent } from '@app/components/quick-chart/quick-chart.component'; import { ToasterModule } from 'angular2-toaster'; -import { ApplicationsListComponent } from './components/applications-list/applications-list.component'; -import { DashboardComponent } from './components/dashboard/dashboard.component'; -import { ActivitiesComponent } from './components/widgets/activities/activities.component'; -import { HistoryStatisticsComponent } from './components/widgets/history-statistics/history-statistics.component'; -import { DailyStatisticsComponent } from '@app/components/widgets/daily-statistics/daily-statistics.component'; -import { ExperimentalComponent } from './components/experimental/experimental.component'; -import { NgxTooltipModule } from './components/ngx-tooltip/ngx-tooltip.module'; -import { SendingInformationHttpsComponent } from './components/docs/sending-information-https/sending-information-https.component'; -import { PrivacyPolicyComponent } from './components/privacy-policy/privacy-policy.component'; -import { ProfileComponent } from './components/profile/profile.component'; -import { DeviceEventsActionsComponent } from '@app/components/device-events-actions/device-events-actions.component'; -import { ContactDetailsComponent } from './components/contact-details/contact-details.component'; -import { IfExperimentalComponent } from './components/if-experimental/if-experimental.component'; -import { GpsComponent } from '@app/components/gps/gps.component'; -import { D3neComponent } from './components/d3ne/d3ne.component'; -import { LampCardComponent } from '@app/components/widgets/lamp-card//lamp-card.component'; -import { HumidityComponent } from '@app/components/widgets/humidity/humidity.component'; -import { CO2WidgetComponent } from '@app/components/widgets/co2-widget/co2-widget.component'; +import { NgxTooltipModule } from '@app/components/ngx-tooltip/ngx-tooltip.module'; +import { PrivacyPolicyComponent } from '@app/components/privacy-policy/privacy-policy.component'; +import { ProfileComponent } from '@app/components/profile/profile.component'; +import { ContactDetailsComponent } from '@app/components/contact-details/contact-details.component'; import { TranslateModule } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core'; import { Ng5BasicModule } from './ng5-basic/ng5-basic.module'; import pl from './translations/pl'; import fa from './translations/fa'; import { GlobalizationService } from '@app/services/globalization.service'; -import { RestfulComponent } from '@app/components/docs/restful/restful.component'; -import { IfNotEnglishComponent } from './components/if-not-english/if-not-english.component'; -import { WaterBubbleComponent } from './components/water-bubble/water-bubble.component'; -import { Co2Component } from './components/co2/co2.component'; import { DOCUMENT } from '@angular/common'; import { UsersModule } from '@app/users/users.module'; import { NgUikitModule } from '@app/ng-uikit/ng-uikit.module'; import { CalendarModule } from 'angular-calendar'; -import { AngularCalendarComponent } from './components/angular-calendar/angular-calendar.component'; +import { AngularCalendarComponent } from '@app/boilerplate/angular-calendar/angular-calendar.component'; +import { IotModule } from '@app/iot/iot.module'; declare var require: any; const Highcharts = require('highcharts/highstock'); @@ -98,17 +59,15 @@ window['Highcharts'] = Highcharts; }) export class AppComponent implements OnInit { constructor ( - private realtime: RealtimeService, private translate: TranslateService, private globalization: GlobalizationService, @Inject(DOCUMENT) private document: Document ) { - this.realtime.ActivateRealtime(); this.RestoreLanguage(); } ngOnInit() { - this.globalization.layoutDirectionEmmiter.subscribe(direction => { + this.globalization.layoutDirectionEmitter.subscribe(direction => { this.document.body.setAttribute('dir', direction); }); } @@ -119,7 +78,6 @@ export class AppComponent implements OnInit { if (_lang === 'en' || _lang === 'pl' || _lang === 'fa') { lang = _lang; } - this.translate.setTranslation('pl', pl); this.translate.setTranslation('fa', fa); this.translate.use(lang); @@ -135,68 +93,28 @@ export class AppComponent implements OnInit { SettingsComponent, PageHeaderComponent, TextInputComponent, - DocsApiWorkaroundComponent, - DeviceSingleComponent, - ProgressLineComponent, RadioInputComponent, SelectInputComponent, - DailyStatisticsComponent, SidebarWidgetComponent, CheckboxInputComponent, - DevicesComponent, - LampCardComponent, - HumidityComponent, - ActivityWidgetComponent, - LocationsComponent, - ActivityComponent, - DeviceGeneralInformationComponent, - LocationRowComponent, - LocationSingleComponent, - OutputPinViewComponent, - NavigationComponent, - DeviceTemperatureComponent, - DeviceLampComponent, - DeviceCO2Component, - DeviceHumidityComponent, - SwitchWidgetsComponent, - IconWidgetsComponent, - PlacesComponent, - DocsComponent, QuickChartComponent, - IndexComponent, UserWidgetComponent, GalleryComponent, LoadingComponent, - StatisticsComponent, - ApplicationsListComponent, - DevicesComponent, - CO2WidgetComponent, - LocationsComponent, - DashboardComponent, - ActivitiesComponent, - HistoryStatisticsComponent, - ExperimentalComponent, - SendingInformationHttpsComponent, PrivacyPolicyComponent, ProfileComponent, - DeviceEventsActionsComponent, ContactDetailsComponent, - IfExperimentalComponent, - GpsComponent, - D3neComponent, - RestfulComponent, - IfNotEnglishComponent, - WaterBubbleComponent, - Co2Component, AngularCalendarComponent, + OutputPinViewComponent, + NavigationComponent, ], imports: [ - RealtimeDocumentModule, NgxTooltipModule, BrowserAnimationsModule, Ng5BasicModule, BrowserModule, FormsModule, + IotModule, UsersModule, TranslateModule.forRoot(), CalendarModule.forRoot(), @@ -207,10 +125,8 @@ export class AppComponent implements OnInit { appReducersGenerator() ], providers: [ - RealtimeService, PermissionsService, RequestsService, - RealtimeService, MockService, ActionsService, NotificationService, @@ -234,9 +150,4 @@ export class AppComponent implements OnInit { }) export class AppModule { - constructor ( - private realtime: RealtimeService, - ) { - // Realtime service is imported intentionally - } } diff --git a/src/app/app.navigation.ts b/src/app/app.navigation.ts index 3b6d080e..9c157b00 100644 --- a/src/app/app.navigation.ts +++ b/src/app/app.navigation.ts @@ -1,88 +1,13 @@ import { environment } from 'environments/environment'; import { DefaultUsersModuleNavigation } from '@app/users/users.module'; import { NgxMenuItem } from '@app/ng5-basic/ngx-sidebar/ngx-sidebar.module'; +import { DefaultIotModuleNavigation } from '@app/iot/iot.module'; +import { DefaultBoilerPlateModuleNavigation } from '@app/boilerplate/boilerplate.module'; + export const navigation: NgxMenuItem[] = [ - { - link: '/index', - icon: 'icon-home', - title: 'Home', - class: 'home' - }, - { - icon: 'icon-cogs', - title: 'Components', - children: [ - { - link: '/angular-calendar', - title: 'Angular Calendar', - icon: 'icon-calendar' - }, - ] - }, - { - icon: 'icon-devices_other', - title: 'Devices', - permissions: ['DEVICES::VIEW'], - class: 'device', - auth: true, - children: [ - { - link: '/device/create', - icon: '', - title: 'Create a device', - permissions: ['DEVICES::VIEW'], - auth: true, - class: 'device-create' - }, - { - link: '/devices', - icon: '', - title: 'Devices List', - permissions: ['DEVICES::VIEW'], - auth: true, - class: 'device-list', - } - ] - }, - { - icon: 'icon-location_searching', - title: 'Locations', - class: 'location', - children: [ - { - link: '/location/new', - icon: '', - title: 'Create a location', - permissions: ['LOCATIONS::VIEW'], - auth: true, - class: 'location-create' - }, - { - link: '/locations', - icon: '', - title: 'View Locations', - permissions: ['LOCATIONS::VIEW'], - auth: true, - class: 'location-list' - }, - ] - }, - { - icon: 'icon-visibility', - title: 'Monitoring', - class: 'monitoring', - children: [ - { - link: '/monitoring/manage-contacts', - icon: '', - title: 'Manage contacts', - permissions: ['LOCATIONS::VIEW'], - auth: true, - class: 'manage-contacts' - }, - ] - }, + ...DefaultBoilerPlateModuleNavigation, DefaultUsersModuleNavigation, + ...DefaultIotModuleNavigation, ! environment.production ? { link: '/gallery', icon: 'icon-attach_file', @@ -92,69 +17,4 @@ export const navigation: NgxMenuItem[] = [ class: 'gallery', focused: true, } : null, - { - title: 'Integration', - icon: 'icon-link', - children: [ - { - link: '/token', - icon: 'icon-settings', - title: 'Access tokens', - class: 'settings', - auth: true - }, - { - // link: '/docs', - icon: 'icon-help', - title: 'documents', - class: 'docs', - children: [ - { - title: 'Introduction', - class: 'docs-introduction', - link: '/docs' - }, - { - title: 'Restful API', - class: 'docs-restful-api', - link: '/docs/restful-api' - }, - { - title: 'Sending information', - class: 'docs-sending-information', - link: '/docs/sending-information-over-https' - }, - - ] - }, - ] - }, - ! environment.production ? { - icon: 'icon-fingerprint', - title: 'Experimental', - class: 'experimental', - children: [ - { - link: '/experimental', - title: 'Introduction', - class: 'introduction', - permissions: ['LOCATIONS::VIEW'], - auth: true, - }, - { - link: '/gps', - icon: '', - title: 'GPS Location', - permissions: ['LOCATIONS::VIEW'], - auth: true, - class: 'gps-location' - }, - ] - } : null, - { - link: '/login', - icon: 'icon-power_settings_new', - title: 'Logout', - class: 'logout' - } ]; diff --git a/src/app/app.reducers.ts b/src/app/app.reducers.ts index 9a74368d..7deb2df3 100644 --- a/src/app/app.reducers.ts +++ b/src/app/app.reducers.ts @@ -1,17 +1,13 @@ -import { devicesReducer } from '@app/data-layer/devices.reducer'; -import { locationsReducer } from '@app/data-layer/locations.reducer'; + import { activitiesReducer } from '@app/data-layer/activity.reducer'; import { notificationsReducer } from '@app/data-layer/notifications.reducer'; -import { unconnectedReducer } from '@app/data-layer/unconnectedSources.reducer'; + import { StoreModule } from '@ngrx/store'; export function appReducersGenerator () { return StoreModule.forRoot({ - devices: devicesReducer, - locations: locationsReducer, activities: activitiesReducer, - unconnectedSources: unconnectedReducer, notifications: notificationsReducer, }); } diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts index de64cf11..f76718c2 100644 --- a/src/app/app.routes.ts +++ b/src/app/app.routes.ts @@ -1,26 +1,15 @@ import { RouterModule, Routes } from '@angular/router'; -import { IndexComponent } from '@components/index/index.component'; -import { LocationsComponent } from '@components/locations/locations.component'; import { SettingsComponent } from '@components/settings/settings.component'; -import { DevicesComponent } from '@components/devices/devices.component'; -import { ActivityComponent } from '@components/activity/activity.component'; -import { LocationSingleComponent } from '@components/locations/location-single/location-single.component'; import { GalleryComponent } from '@components/gallery/gallery.component'; -import { DeviceSingleComponent } from '../app/components/device-single/device-single.component'; -import { DocsComponent } from '@components/docs/docs.component'; import { Route } from '@angular/router'; import { LayoutComponent } from './ng5-basic/layout/layout.component'; import { AuthGuard } from '@services/user.service'; -import { ExperimentalComponent } from '@app/components/experimental/experimental.component'; -import { SendingInformationHttpsComponent } from './components/docs/sending-information-https/sending-information-https.component'; import { PrivacyPolicyComponent } from '@app/components/privacy-policy/privacy-policy.component'; import { ProfileComponent } from '@app/components/profile/profile.component'; -import { DeviceEventsActionsComponent } from '@app/components/device-events-actions/device-events-actions.component'; import { ContactDetailsComponent } from '@app/components/contact-details/contact-details.component'; -import { GpsComponent } from '@app/components/gps/gps.component'; -import { RestfulComponent } from '@app/components/docs/restful/restful.component'; import { userAuthLayoutRoutes } from '@app/users/user-routes'; -import { AngularCalendarComponent } from '@app/components/angular-calendar/angular-calendar.component'; +import { AngularCalendarComponent } from '@app/boilerplate/angular-calendar/angular-calendar.component'; +import { IotAuthLayoutRoutes } from '@app/iot/iot-routes'; export function AuthLayoutChild(component: any, route: string, options: any = {}): Route { return { @@ -42,24 +31,10 @@ export const appRoutes: Routes = [ canActivate: [AuthGuard], component: LayoutComponent, children: [ - AuthLayoutChild (IndexComponent, 'index'), - AuthLayoutChild (LocationsComponent, 'locations'), + ...IotAuthLayoutRoutes, AuthLayoutChild (SettingsComponent, 'token'), - AuthLayoutChild (LocationSingleComponent, 'locations/edit/:id', {data: {mode: 'edit'}}), - AuthLayoutChild (LocationSingleComponent, 'location/new', {data: {mode: 'new'}}), - AuthLayoutChild (ActivityComponent, 'activities'), - AuthLayoutChild (GpsComponent, 'gps'), - AuthLayoutChild (ContactDetailsComponent, 'monitoring/manage-contacts'), - AuthLayoutChild (DevicesComponent, 'devices'), - AuthLayoutChild (DeviceSingleComponent, 'device/create'), AuthLayoutChild (ProfileComponent, 'profile'), - AuthLayoutChild (DeviceEventsActionsComponent, 'device/events-and-actions/:id'), - AuthLayoutChild (DeviceSingleComponent, 'device/:id'), - AuthLayoutChild (ExperimentalComponent, 'experimental'), - AuthLayoutChild (DeviceSingleComponent, 'create-device-from-source/:sourceId'), - AuthLayoutChild (DocsComponent, 'docs'), - AuthLayoutChild (SendingInformationHttpsComponent, 'docs/sending-information-over-https'), - AuthLayoutChild (RestfulComponent, 'docs/restful-api'), + AuthLayoutChild (ContactDetailsComponent, 'monitoring/manage-contacts'), AuthLayoutChild (GalleryComponent, 'gallery'), AuthLayoutChild (AngularCalendarComponent, 'angular-calendar'), ...userAuthLayoutRoutes, diff --git a/src/app/components/angular-calendar/angular-calendar.component.html b/src/app/boilerplate/angular-calendar/angular-calendar.component.html similarity index 100% rename from src/app/components/angular-calendar/angular-calendar.component.html rename to src/app/boilerplate/angular-calendar/angular-calendar.component.html diff --git a/src/app/components/angular-calendar/angular-calendar.component.scss b/src/app/boilerplate/angular-calendar/angular-calendar.component.scss similarity index 100% rename from src/app/components/angular-calendar/angular-calendar.component.scss rename to src/app/boilerplate/angular-calendar/angular-calendar.component.scss diff --git a/src/app/components/angular-calendar/angular-calendar.component.spec.ts b/src/app/boilerplate/angular-calendar/angular-calendar.component.spec.ts similarity index 100% rename from src/app/components/angular-calendar/angular-calendar.component.spec.ts rename to src/app/boilerplate/angular-calendar/angular-calendar.component.spec.ts diff --git a/src/app/components/angular-calendar/angular-calendar.component.ts b/src/app/boilerplate/angular-calendar/angular-calendar.component.ts similarity index 100% rename from src/app/components/angular-calendar/angular-calendar.component.ts rename to src/app/boilerplate/angular-calendar/angular-calendar.component.ts diff --git a/src/app/boilerplate/boilerplate.module.ts b/src/app/boilerplate/boilerplate.module.ts new file mode 100644 index 00000000..869f555c --- /dev/null +++ b/src/app/boilerplate/boilerplate.module.ts @@ -0,0 +1,66 @@ +import { NgModule, } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { NgUikitModule } from '@app/ng-uikit/ng-uikit.module'; +import { TranslateModule } from '@ngx-translate/core'; +import { RouterModule } from '@angular/router'; +import { NgxTooltipModule } from '../components/ngx-tooltip/ngx-tooltip.module'; +import { NgbModule, NgbModalModule } from '@ng-bootstrap/ng-bootstrap'; +import { ReactiveFormsModule, FormsModule } from '@angular/forms'; +import { UserCommonService } from '@app/users/user-common.service'; +import { UserMockService } from '@app/users/user-mocks.service'; +import { UserRequestsService } from '@app/users/user-requests.service'; +import { HTTP_INTERCEPTORS } from '@angular/common/http'; +import { UserMockInterceptor } from '@app/users/user-mock.interceptor'; +import { environment } from 'environments/environment'; +import { userModuleReducersGenerator } from '@app/users/user-module.reducers'; + +@NgModule({ + imports: [ + CommonModule, + NgUikitModule, + RouterModule.forChild([]), + TranslateModule.forRoot(), + NgxTooltipModule, + ReactiveFormsModule, + FormsModule, + NgbModule.forRoot(), + NgbModalModule.forRoot(), + userModuleReducersGenerator(), + ], + providers: [ + UserCommonService, + UserMockService, + UserRequestsService, + !environment.targetAPI ? { provide: HTTP_INTERCEPTORS, useClass: UserMockInterceptor, multi: true } : [], + ], + declarations: [ + + ] +}) +export class BoilerplateModule { } + +export const DefaultBoilerPlateModuleNavigation = [ + { + link: '/index', + icon: 'icon-home', + title: 'Home', + class: 'home' + }, + { + icon: 'icon-cogs', + title: 'Components', + children: [ + { + link: '/angular-calendar', + title: 'Angular Calendar', + icon: 'icon-calendar' + }, + ] + }, + { + link: '/login', + icon: 'icon-power_settings_new', + title: 'Logout', + class: 'logout' + }, +]; diff --git a/src/app/components/applications-list/applications-list.component.html b/src/app/components/applications-list/applications-list.component.html deleted file mode 100644 index c6786038..00000000 --- a/src/app/components/applications-list/applications-list.component.html +++ /dev/null @@ -1,3 +0,0 @@ -
- -
\ No newline at end of file diff --git a/src/app/components/applications-list/applications-list.component.scss b/src/app/components/applications-list/applications-list.component.scss deleted file mode 100644 index 803d6db2..00000000 --- a/src/app/components/applications-list/applications-list.component.scss +++ /dev/null @@ -1,18 +0,0 @@ -.application-list-container{ - width: 55px; - height: 55px; - align-items: center; - justify-content: center; - display: flex; - font-size: 24px; - color: #aaa; - position: relative; - cursor: pointer; - &:hover i{ - color: #4c84ff; - } - @media(max-width: 400px) { - width: 45px; - height: 50px; - } -} \ No newline at end of file diff --git a/src/app/components/applications-list/applications-list.component.spec.ts b/src/app/components/applications-list/applications-list.component.spec.ts deleted file mode 100644 index de404335..00000000 --- a/src/app/components/applications-list/applications-list.component.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; - -import { ApplicationsListComponent } from './applications-list.component'; - -describe('ApplicationsListComponent', () => { - let component: ApplicationsListComponent; - let fixture: ComponentFixture; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ ApplicationsListComponent ] - }) - .compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(ApplicationsListComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/src/app/components/applications-list/applications-list.component.ts b/src/app/components/applications-list/applications-list.component.ts deleted file mode 100644 index f8b61c1e..00000000 --- a/src/app/components/applications-list/applications-list.component.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Component, OnInit } from '@angular/core'; - -@Component({ - selector: 'app-applications-list', - templateUrl: './applications-list.component.html', - styleUrls: ['./applications-list.component.scss'] -}) -export class ApplicationsListComponent implements OnInit { - - constructor() { } - - ngOnInit() { - } - -} diff --git a/src/app/components/dashboard/dashboard.component.html b/src/app/components/dashboard/dashboard.component.html deleted file mode 100644 index d5da541b..00000000 --- a/src/app/components/dashboard/dashboard.component.html +++ /dev/null @@ -1,102 +0,0 @@ -
-
-
-
-
-

Location

-

Number of the locations

-
-
- 2 -
-
-
-
-
-
-
-
-

Widget

-

Number of the widgets

-
-
- 15 -
-
-
-
-
-
-
-
-

Tempreture

-

Number of the tempretures

-
-
- 3 -
-
-
-
-
-
-
-
-

Lights

-

Number of the lights

-
-
- 6 -
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
- -
-
-
\ No newline at end of file diff --git a/src/app/components/dashboard/dashboard.component.scss b/src/app/components/dashboard/dashboard.component.scss deleted file mode 100644 index 2b307bb7..00000000 --- a/src/app/components/dashboard/dashboard.component.scss +++ /dev/null @@ -1,28 +0,0 @@ - -.box-wrapper { - height: auto; - border: 1px solid #eee; - border-radius: 3px; - background: #fff; - box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.14); - padding: 15px; - margin: 15px 0 15px; -} -.no-padding { - padding: 0 !important; -} - -.app-statistics { - h2 { - font-size: 20px; - } - p{ - margin-bottom: 0; - } - .app-statistics-value { - font-size: 35px; - color: #aaa; - font-weight: 500; - padding-right: 10px; - } -} \ No newline at end of file diff --git a/src/app/components/dashboard/dashboard.component.spec.ts b/src/app/components/dashboard/dashboard.component.spec.ts deleted file mode 100644 index 9c996c37..00000000 --- a/src/app/components/dashboard/dashboard.component.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; - -import { DashboardComponent } from './dashboard.component'; - -describe('DashboardComponent', () => { - let component: DashboardComponent; - let fixture: ComponentFixture; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ DashboardComponent ] - }) - .compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(DashboardComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/src/app/components/dashboard/dashboard.component.ts b/src/app/components/dashboard/dashboard.component.ts deleted file mode 100644 index bf629394..00000000 --- a/src/app/components/dashboard/dashboard.component.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { Component, OnInit } from '@angular/core'; -import { DailyStatistics } from '../../../mocks/dailyStatistics'; -import { HistoryStatistics } from '../../../mocks/historyStatistics'; - -@Component({ - selector: 'app-dashboard', - templateUrl: './dashboard.component.html', - styleUrls: ['./dashboard.component.scss'] -}) -export class DashboardComponent implements OnInit { - public hs = HistoryStatistics; - public ds = DailyStatistics; - public liveData: any; - - constructor() { } - - ngOnInit() { - setInterval(() => { - this.liveData = [new Date().getTime(), Math.floor(Math.random() * 8 + 30)]; - }, 2000); - } - -} diff --git a/src/app/components/profile/profile.component.html b/src/app/components/profile/profile.component.html index 0bf1c87d..6aee3bfc 100644 --- a/src/app/components/profile/profile.component.html +++ b/src/app/components/profile/profile.component.html @@ -51,17 +51,12 @@ name="preferences_language" (change)="ChangeLanguage()" type="text"> - + {{ 'At the moment, for some languages might be not fully covered and you still see english words.' | translate }} {{ 'Plus, we do not store your preference in your account since it\'s an experimental feature.' | translate }} - - - Please try to contribute to this repository if you are interested to add your own language with official support. At the moment we only do support Polish language. - - diff --git a/src/app/components/profile/profile.component.ts b/src/app/components/profile/profile.component.ts index eea05ab5..7ed6504c 100644 --- a/src/app/components/profile/profile.component.ts +++ b/src/app/components/profile/profile.component.ts @@ -15,6 +15,8 @@ import { GlobalizationService } from '@app/services/globalization.service'; }) export class ProfileComponent implements OnInit { public isRequesting = false; + public currentLang = 'en'; + public langs: any[] = []; public response: IResponse = null; public form: IUser = { email: null, @@ -35,10 +37,9 @@ export class ProfileComponent implements OnInit { public translate: TranslateService, public globalization: GlobalizationService, ) { + this.langs = this.globalization.GetLanguages(); } - - public ChangeLanguage () { const lang = this.form.preferences.language; this.translate.setDefaultLang(lang); @@ -48,6 +49,7 @@ export class ProfileComponent implements OnInit { } ngOnInit() { + this.currentLang = this.translate.currentLang; this.form = Object.assign(this.form, this.user.User); } public async SubmitForm () { diff --git a/src/app/components/settings/settings.component.ts b/src/app/components/settings/settings.component.ts index f1137f59..781b8857 100644 --- a/src/app/components/settings/settings.component.ts +++ b/src/app/components/settings/settings.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; -import { RequestsService } from '@app/services/requests.service'; import { IsSuccessEntity } from '@app/common'; +import { IotRequestsService } from '@app/iot/iot-requests.service'; @Component({ selector: 'app-settings', @@ -11,7 +11,7 @@ export class SettingsComponent implements OnInit { private token: string = null; constructor( - private requests: RequestsService, + private requests: IotRequestsService, ) { } public GetDeviceToken () { diff --git a/src/app/definitions.ts b/src/app/definitions.ts index 3bd52e62..6397f4ae 100644 --- a/src/app/definitions.ts +++ b/src/app/definitions.ts @@ -73,13 +73,10 @@ export interface IPermission { * Represents the application store structure */ export interface AppState { - devices: Array; roles: Array; users: Array; notifications: Array; - locations: Array; activities: Array; - unconnectedSources: Array; } /** diff --git a/src/app/components/activity/activity-widget/activity-widget.component.html b/src/app/iot/activity/activity-widget/activity-widget.component.html similarity index 100% rename from src/app/components/activity/activity-widget/activity-widget.component.html rename to src/app/iot/activity/activity-widget/activity-widget.component.html diff --git a/src/app/components/activity/activity-widget/activity-widget.component.scss b/src/app/iot/activity/activity-widget/activity-widget.component.scss similarity index 100% rename from src/app/components/activity/activity-widget/activity-widget.component.scss rename to src/app/iot/activity/activity-widget/activity-widget.component.scss diff --git a/src/app/components/activity/activity-widget/activity-widget.component.ts b/src/app/iot/activity/activity-widget/activity-widget.component.ts similarity index 100% rename from src/app/components/activity/activity-widget/activity-widget.component.ts rename to src/app/iot/activity/activity-widget/activity-widget.component.ts diff --git a/src/app/components/activity/activity.component.html b/src/app/iot/activity/activity.component.html similarity index 100% rename from src/app/components/activity/activity.component.html rename to src/app/iot/activity/activity.component.html diff --git a/src/app/components/activity/activity.component.scss b/src/app/iot/activity/activity.component.scss similarity index 100% rename from src/app/components/activity/activity.component.scss rename to src/app/iot/activity/activity.component.scss diff --git a/src/app/components/activity/activity.component.ts b/src/app/iot/activity/activity.component.ts similarity index 100% rename from src/app/components/activity/activity.component.ts rename to src/app/iot/activity/activity.component.ts diff --git a/src/app/components/checkbox-switch.scss b/src/app/iot/checkbox-switch.scss similarity index 100% rename from src/app/components/checkbox-switch.scss rename to src/app/iot/checkbox-switch.scss diff --git a/src/app/components/co2/co2.component.html b/src/app/iot/co2/co2.component.html similarity index 100% rename from src/app/components/co2/co2.component.html rename to src/app/iot/co2/co2.component.html diff --git a/src/app/components/co2/co2.component.scss b/src/app/iot/co2/co2.component.scss similarity index 100% rename from src/app/components/co2/co2.component.scss rename to src/app/iot/co2/co2.component.scss diff --git a/src/app/components/co2/co2.component.spec.ts b/src/app/iot/co2/co2.component.spec.ts similarity index 100% rename from src/app/components/co2/co2.component.spec.ts rename to src/app/iot/co2/co2.component.spec.ts diff --git a/src/app/components/co2/co2.component.ts b/src/app/iot/co2/co2.component.ts similarity index 100% rename from src/app/components/co2/co2.component.ts rename to src/app/iot/co2/co2.component.ts diff --git a/src/app/components/d3ne/d3ne.component.html b/src/app/iot/d3ne/d3ne.component.html similarity index 100% rename from src/app/components/d3ne/d3ne.component.html rename to src/app/iot/d3ne/d3ne.component.html diff --git a/src/app/components/d3ne/d3ne.component.scss b/src/app/iot/d3ne/d3ne.component.scss similarity index 100% rename from src/app/components/d3ne/d3ne.component.scss rename to src/app/iot/d3ne/d3ne.component.scss diff --git a/src/app/components/d3ne/d3ne.component.spec.ts b/src/app/iot/d3ne/d3ne.component.spec.ts similarity index 100% rename from src/app/components/d3ne/d3ne.component.spec.ts rename to src/app/iot/d3ne/d3ne.component.spec.ts diff --git a/src/app/components/d3ne/d3ne.component.ts b/src/app/iot/d3ne/d3ne.component.ts similarity index 100% rename from src/app/components/d3ne/d3ne.component.ts rename to src/app/iot/d3ne/d3ne.component.ts diff --git a/src/app/components/device-co2/device-co2.component.html b/src/app/iot/device-co2/device-co2.component.html similarity index 100% rename from src/app/components/device-co2/device-co2.component.html rename to src/app/iot/device-co2/device-co2.component.html diff --git a/src/app/components/device-co2/device-co2.component.scss b/src/app/iot/device-co2/device-co2.component.scss similarity index 100% rename from src/app/components/device-co2/device-co2.component.scss rename to src/app/iot/device-co2/device-co2.component.scss diff --git a/src/app/components/device-co2/device-co2.component.ts b/src/app/iot/device-co2/device-co2.component.ts similarity index 100% rename from src/app/components/device-co2/device-co2.component.ts rename to src/app/iot/device-co2/device-co2.component.ts diff --git a/src/app/components/device-events-actions/device-events-actions.component.html b/src/app/iot/device-events-actions/device-events-actions.component.html similarity index 100% rename from src/app/components/device-events-actions/device-events-actions.component.html rename to src/app/iot/device-events-actions/device-events-actions.component.html diff --git a/src/app/components/device-events-actions/device-events-actions.component.scss b/src/app/iot/device-events-actions/device-events-actions.component.scss similarity index 100% rename from src/app/components/device-events-actions/device-events-actions.component.scss rename to src/app/iot/device-events-actions/device-events-actions.component.scss diff --git a/src/app/components/device-events-actions/device-events-actions.component.spec.ts b/src/app/iot/device-events-actions/device-events-actions.component.spec.ts similarity index 100% rename from src/app/components/device-events-actions/device-events-actions.component.spec.ts rename to src/app/iot/device-events-actions/device-events-actions.component.spec.ts diff --git a/src/app/components/device-events-actions/device-events-actions.component.ts b/src/app/iot/device-events-actions/device-events-actions.component.ts similarity index 100% rename from src/app/components/device-events-actions/device-events-actions.component.ts rename to src/app/iot/device-events-actions/device-events-actions.component.ts diff --git a/src/app/components/device-general-information/device-general-information.component.html b/src/app/iot/device-general-information/device-general-information.component.html similarity index 100% rename from src/app/components/device-general-information/device-general-information.component.html rename to src/app/iot/device-general-information/device-general-information.component.html diff --git a/src/app/components/device-general-information/device-general-information.component.scss b/src/app/iot/device-general-information/device-general-information.component.scss similarity index 100% rename from src/app/components/device-general-information/device-general-information.component.scss rename to src/app/iot/device-general-information/device-general-information.component.scss diff --git a/src/app/components/device-general-information/device-general-information.component.ts b/src/app/iot/device-general-information/device-general-information.component.ts similarity index 80% rename from src/app/components/device-general-information/device-general-information.component.ts rename to src/app/iot/device-general-information/device-general-information.component.ts index c3227155..ee8d5a5b 100644 --- a/src/app/components/device-general-information/device-general-information.component.ts +++ b/src/app/iot/device-general-information/device-general-information.component.ts @@ -1,8 +1,9 @@ import { Component, OnInit, OnDestroy, Input, Output, EventEmitter } from '@angular/core'; -import { CloudDevice, AppState } from '@app/definitions'; +import { CloudDevice } from '@app/definitions'; import { Store } from '@ngrx/store'; import { IResponse } from 'response-type'; import { error } from '@app/common'; +import { IotModuleState } from '@app/iot/iot.module.defs'; @Component({ selector: 'app-device-general-information', @@ -23,13 +24,13 @@ export class DeviceGeneralInformationComponent implements OnInit, OnDestroy { public error = error; constructor ( - private store: Store, + private store: Store, ) { } ngOnInit() { - this.ref = this.store.select('locations').subscribe((data) => { - this.locations = data; + this.ref = this.store.select('iotModule').subscribe(({locations}) => { + this.locations = locations; }); } diff --git a/src/app/components/device-humidity/device-humidity.component.html b/src/app/iot/device-humidity/device-humidity.component.html similarity index 100% rename from src/app/components/device-humidity/device-humidity.component.html rename to src/app/iot/device-humidity/device-humidity.component.html diff --git a/src/app/components/device-humidity/device-humidity.component.scss b/src/app/iot/device-humidity/device-humidity.component.scss similarity index 100% rename from src/app/components/device-humidity/device-humidity.component.scss rename to src/app/iot/device-humidity/device-humidity.component.scss diff --git a/src/app/components/device-humidity/device-humidity.component.ts b/src/app/iot/device-humidity/device-humidity.component.ts similarity index 100% rename from src/app/components/device-humidity/device-humidity.component.ts rename to src/app/iot/device-humidity/device-humidity.component.ts diff --git a/src/app/components/device-lamp/device-lamp.component.html b/src/app/iot/device-lamp/device-lamp.component.html similarity index 100% rename from src/app/components/device-lamp/device-lamp.component.html rename to src/app/iot/device-lamp/device-lamp.component.html diff --git a/src/app/components/device-lamp/device-lamp.component.scss b/src/app/iot/device-lamp/device-lamp.component.scss similarity index 100% rename from src/app/components/device-lamp/device-lamp.component.scss rename to src/app/iot/device-lamp/device-lamp.component.scss diff --git a/src/app/components/device-lamp/device-lamp.component.ts b/src/app/iot/device-lamp/device-lamp.component.ts similarity index 100% rename from src/app/components/device-lamp/device-lamp.component.ts rename to src/app/iot/device-lamp/device-lamp.component.ts diff --git a/src/app/components/device-single/device-single.component.html b/src/app/iot/device-single/device-single.component.html similarity index 100% rename from src/app/components/device-single/device-single.component.html rename to src/app/iot/device-single/device-single.component.html diff --git a/src/app/components/device-single/device-single.component.scss b/src/app/iot/device-single/device-single.component.scss similarity index 100% rename from src/app/components/device-single/device-single.component.scss rename to src/app/iot/device-single/device-single.component.scss diff --git a/src/app/components/device-single/device-single.component.ts b/src/app/iot/device-single/device-single.component.ts similarity index 90% rename from src/app/components/device-single/device-single.component.ts rename to src/app/iot/device-single/device-single.component.ts index e34370e9..00247f5a 100644 --- a/src/app/components/device-single/device-single.component.ts +++ b/src/app/iot/device-single/device-single.component.ts @@ -1,8 +1,7 @@ import { Component, OnInit, OnDestroy } from '@angular/core'; -import { CloudDevice, CloudDeviceType, AppState } from '@app/definitions'; +import { CloudDevice, CloudDeviceType } from '@app/definitions'; import { ActivatedRoute, Router } from '@angular/router'; import { Store } from '@ngrx/store'; -import { RequestsService } from '@app/services/requests.service'; import 'rxjs/add/operator/toPromise'; import { IResponse } from 'response-type'; import { error } from '@app/common'; @@ -11,6 +10,8 @@ import { TranslateService } from '@ngx-translate/core'; import 'rxjs/add/observable/combineLatest'; import { Observable } from 'rxjs/Observable'; import { ActionsService } from '@app/services/actions.service'; +import { IotModuleState } from '@app/iot/iot.module.defs'; +import { IotRequestsService } from '@app/iot/iot-requests.service'; @Component({ selector: 'app-device-single', @@ -30,10 +31,10 @@ export class DeviceSingleComponent implements OnInit, OnDestroy { public error = error; constructor( private route: ActivatedRoute, - private store: Store, + private store: Store, private router: Router, private actions: ActionsService, - private requests: RequestsService, + private requests: IotRequestsService, private notification: NotificationService, private translate: TranslateService, ) { @@ -41,9 +42,9 @@ export class DeviceSingleComponent implements OnInit, OnDestroy { async ngOnInit() { Observable.combineLatest( - this.store.select('devices'), + this.store.select('iotModule'), this.route.params - ).subscribe(([devices, params]) => { + ).subscribe(([{devices}, params]) => { if (params.sourceId) { this.form.datasource = params.sourceId; } diff --git a/src/app/components/device-temperature/device-temperature.component.html b/src/app/iot/device-temperature/device-temperature.component.html similarity index 100% rename from src/app/components/device-temperature/device-temperature.component.html rename to src/app/iot/device-temperature/device-temperature.component.html diff --git a/src/app/components/device-temperature/device-temperature.component.scss b/src/app/iot/device-temperature/device-temperature.component.scss similarity index 100% rename from src/app/components/device-temperature/device-temperature.component.scss rename to src/app/iot/device-temperature/device-temperature.component.scss diff --git a/src/app/components/device-temperature/device-temperature.component.ts b/src/app/iot/device-temperature/device-temperature.component.ts similarity index 100% rename from src/app/components/device-temperature/device-temperature.component.ts rename to src/app/iot/device-temperature/device-temperature.component.ts diff --git a/src/app/components/devices/devices.component.html b/src/app/iot/devices/devices.component.html similarity index 100% rename from src/app/components/devices/devices.component.html rename to src/app/iot/devices/devices.component.html diff --git a/src/app/components/devices/devices.component.scss b/src/app/iot/devices/devices.component.scss similarity index 100% rename from src/app/components/devices/devices.component.scss rename to src/app/iot/devices/devices.component.scss diff --git a/src/app/components/devices/devices.component.ts b/src/app/iot/devices/devices.component.ts similarity index 71% rename from src/app/components/devices/devices.component.ts rename to src/app/iot/devices/devices.component.ts index 48f51a81..dbddf718 100644 --- a/src/app/components/devices/devices.component.ts +++ b/src/app/iot/devices/devices.component.ts @@ -1,10 +1,11 @@ import { Component, OnInit, OnDestroy, ChangeDetectorRef } from '@angular/core'; -import { AppState, ILocation, DataSource, CloudDevice } from '@app/definitions'; +import { ILocation, DataSource, CloudDevice } from '@app/definitions'; import { Store } from '@ngrx/store'; -import { RequestsService } from '@services/requests.service'; import { Router } from '@angular/router'; import { NotificationService } from '@app/services/notification.service'; import { TranslateService } from '@ngx-translate/core'; +import { IotModuleState } from '@app/iot/iot.module.defs'; +import { IotRequestsService } from '@app/iot/iot-requests.service'; @Component({ selector: 'app-devices', @@ -19,10 +20,10 @@ export class DevicesComponent implements OnInit, OnDestroy { private _ref1: any = null; private _ref2 = null; constructor ( - private requests: RequestsService, + private requests: IotRequestsService, public chRef: ChangeDetectorRef, private router: Router, - private store: Store, + private store: Store, private notification: NotificationService, private translate: TranslateService, @@ -30,15 +31,16 @@ export class DevicesComponent implements OnInit, OnDestroy { } ngOnInit() { - this._ref1 = this.store.select('devices').subscribe(collection => { - this.devices = collection; + this._ref1 = this.store.select('iotModule').subscribe(({devices}) => { + this.devices = devices; }); - this._ref2 = this.store.select('locations').subscribe(collection => { - this.locations = (collection as Array); + this._ref2 = this.store.select('iotModule').subscribe(({locations}) => { + this.locations = (locations as Array); }); - this.store.select('unconnectedSources').subscribe(sources => { - this.unconnected = sources; + this.store.select('iotModule').subscribe(({unconnectedSources}) => { + this.unconnected = unconnectedSources; }); + this.requests.getDevices(); } public FormatDate (value: Date) { if ( ! value ) { diff --git a/src/app/components/docs/docs-api-workaround/docs-api-workaround.component.html b/src/app/iot/docs/docs-api-workaround/docs-api-workaround.component.html similarity index 100% rename from src/app/components/docs/docs-api-workaround/docs-api-workaround.component.html rename to src/app/iot/docs/docs-api-workaround/docs-api-workaround.component.html diff --git a/src/app/components/docs/docs-api-workaround/docs-api-workaround.component.scss b/src/app/iot/docs/docs-api-workaround/docs-api-workaround.component.scss similarity index 100% rename from src/app/components/docs/docs-api-workaround/docs-api-workaround.component.scss rename to src/app/iot/docs/docs-api-workaround/docs-api-workaround.component.scss diff --git a/src/app/components/docs/docs-api-workaround/docs-api-workaround.component.ts b/src/app/iot/docs/docs-api-workaround/docs-api-workaround.component.ts similarity index 100% rename from src/app/components/docs/docs-api-workaround/docs-api-workaround.component.ts rename to src/app/iot/docs/docs-api-workaround/docs-api-workaround.component.ts diff --git a/src/app/components/docs/docs.component.html b/src/app/iot/docs/docs.component.html similarity index 100% rename from src/app/components/docs/docs.component.html rename to src/app/iot/docs/docs.component.html diff --git a/src/app/components/docs/docs.component.scss b/src/app/iot/docs/docs.component.scss similarity index 100% rename from src/app/components/docs/docs.component.scss rename to src/app/iot/docs/docs.component.scss diff --git a/src/app/components/docs/docs.component.ts b/src/app/iot/docs/docs.component.ts similarity index 89% rename from src/app/components/docs/docs.component.ts rename to src/app/iot/docs/docs.component.ts index 966bcc1b..de43dfff 100644 --- a/src/app/components/docs/docs.component.ts +++ b/src/app/iot/docs/docs.component.ts @@ -1,8 +1,8 @@ import { Component, OnInit } from '@angular/core'; import { IResponse } from 'response-type'; import { environment } from 'environments/environment'; -import { RequestsService } from '@app/services/requests.service'; import { IsSuccessEntity } from '@app/common'; +import { IotRequestsService } from '@app/iot/iot-requests.service'; @Component({ selector: 'app-docs', @@ -26,9 +26,8 @@ export class DocsComponent implements OnInit { 'x-token': '-token-', }; - constructor ( - private requests: RequestsService + private requests: IotRequestsService ) { } diff --git a/src/app/components/docs/docs.styling.scss b/src/app/iot/docs/docs.styling.scss similarity index 100% rename from src/app/components/docs/docs.styling.scss rename to src/app/iot/docs/docs.styling.scss diff --git a/src/app/components/docs/restful/restful.component.html b/src/app/iot/docs/restful/restful.component.html similarity index 100% rename from src/app/components/docs/restful/restful.component.html rename to src/app/iot/docs/restful/restful.component.html diff --git a/src/app/components/docs/restful/restful.component.scss b/src/app/iot/docs/restful/restful.component.scss similarity index 100% rename from src/app/components/docs/restful/restful.component.scss rename to src/app/iot/docs/restful/restful.component.scss diff --git a/src/app/components/docs/restful/restful.component.spec.ts b/src/app/iot/docs/restful/restful.component.spec.ts similarity index 100% rename from src/app/components/docs/restful/restful.component.spec.ts rename to src/app/iot/docs/restful/restful.component.spec.ts diff --git a/src/app/components/docs/restful/restful.component.ts b/src/app/iot/docs/restful/restful.component.ts similarity index 100% rename from src/app/components/docs/restful/restful.component.ts rename to src/app/iot/docs/restful/restful.component.ts diff --git a/src/app/components/docs/sending-information-https/sending-information-https.component.html b/src/app/iot/docs/sending-information-https/sending-information-https.component.html similarity index 100% rename from src/app/components/docs/sending-information-https/sending-information-https.component.html rename to src/app/iot/docs/sending-information-https/sending-information-https.component.html diff --git a/src/app/components/docs/sending-information-https/sending-information-https.component.scss b/src/app/iot/docs/sending-information-https/sending-information-https.component.scss similarity index 100% rename from src/app/components/docs/sending-information-https/sending-information-https.component.scss rename to src/app/iot/docs/sending-information-https/sending-information-https.component.scss diff --git a/src/app/components/docs/sending-information-https/sending-information-https.component.spec.ts b/src/app/iot/docs/sending-information-https/sending-information-https.component.spec.ts similarity index 100% rename from src/app/components/docs/sending-information-https/sending-information-https.component.spec.ts rename to src/app/iot/docs/sending-information-https/sending-information-https.component.spec.ts diff --git a/src/app/components/docs/sending-information-https/sending-information-https.component.ts b/src/app/iot/docs/sending-information-https/sending-information-https.component.ts similarity index 94% rename from src/app/components/docs/sending-information-https/sending-information-https.component.ts rename to src/app/iot/docs/sending-information-https/sending-information-https.component.ts index 3fb1ef67..7e14d99c 100644 --- a/src/app/components/docs/sending-information-https/sending-information-https.component.ts +++ b/src/app/iot/docs/sending-information-https/sending-information-https.component.ts @@ -2,8 +2,8 @@ import { Component, OnInit } from '@angular/core'; import { IResponse } from 'response-type'; import { DataSource } from '@app/definitions'; import { environment } from 'environments/environment'; -import { RequestsService } from '@app/services/requests.service'; import { IsSuccessEntity } from '@app/common'; +import { IotRequestsService } from '@app/iot/iot-requests.service'; declare var require: any; const YAML = require('yamljs'); @@ -57,7 +57,7 @@ export class SendingInformationHttpsComponent implements OnInit { } }; constructor( - private requests: RequestsService, + private requests: IotRequestsService, ) { } async ngOnInit() { diff --git a/src/app/components/experimental/experimental.component.html b/src/app/iot/experimental/experimental.component.html similarity index 100% rename from src/app/components/experimental/experimental.component.html rename to src/app/iot/experimental/experimental.component.html diff --git a/src/app/components/experimental/experimental.component.scss b/src/app/iot/experimental/experimental.component.scss similarity index 100% rename from src/app/components/experimental/experimental.component.scss rename to src/app/iot/experimental/experimental.component.scss diff --git a/src/app/components/experimental/experimental.component.spec.ts b/src/app/iot/experimental/experimental.component.spec.ts similarity index 100% rename from src/app/components/experimental/experimental.component.spec.ts rename to src/app/iot/experimental/experimental.component.spec.ts diff --git a/src/app/components/experimental/experimental.component.ts b/src/app/iot/experimental/experimental.component.ts similarity index 100% rename from src/app/components/experimental/experimental.component.ts rename to src/app/iot/experimental/experimental.component.ts diff --git a/src/app/components/gps/gps.component.html b/src/app/iot/gps/gps.component.html similarity index 100% rename from src/app/components/gps/gps.component.html rename to src/app/iot/gps/gps.component.html diff --git a/src/app/components/gps/gps.component.scss b/src/app/iot/gps/gps.component.scss similarity index 100% rename from src/app/components/gps/gps.component.scss rename to src/app/iot/gps/gps.component.scss diff --git a/src/app/components/gps/gps.component.spec.ts b/src/app/iot/gps/gps.component.spec.ts similarity index 100% rename from src/app/components/gps/gps.component.spec.ts rename to src/app/iot/gps/gps.component.spec.ts diff --git a/src/app/components/gps/gps.component.ts b/src/app/iot/gps/gps.component.ts similarity index 100% rename from src/app/components/gps/gps.component.ts rename to src/app/iot/gps/gps.component.ts diff --git a/src/app/components/if-not-english/if-not-english.component.html b/src/app/iot/if-not-english/if-not-english.component.html similarity index 100% rename from src/app/components/if-not-english/if-not-english.component.html rename to src/app/iot/if-not-english/if-not-english.component.html diff --git a/src/app/components/if-not-english/if-not-english.component.scss b/src/app/iot/if-not-english/if-not-english.component.scss similarity index 100% rename from src/app/components/if-not-english/if-not-english.component.scss rename to src/app/iot/if-not-english/if-not-english.component.scss diff --git a/src/app/components/if-not-english/if-not-english.component.spec.ts b/src/app/iot/if-not-english/if-not-english.component.spec.ts similarity index 100% rename from src/app/components/if-not-english/if-not-english.component.spec.ts rename to src/app/iot/if-not-english/if-not-english.component.spec.ts diff --git a/src/app/components/if-not-english/if-not-english.component.ts b/src/app/iot/if-not-english/if-not-english.component.ts similarity index 100% rename from src/app/components/if-not-english/if-not-english.component.ts rename to src/app/iot/if-not-english/if-not-english.component.ts diff --git a/src/app/components/index/icon-widgets/icon-widgets.component.html b/src/app/iot/index/icon-widgets/icon-widgets.component.html similarity index 100% rename from src/app/components/index/icon-widgets/icon-widgets.component.html rename to src/app/iot/index/icon-widgets/icon-widgets.component.html diff --git a/src/app/components/index/icon-widgets/icon-widgets.component.scss b/src/app/iot/index/icon-widgets/icon-widgets.component.scss similarity index 100% rename from src/app/components/index/icon-widgets/icon-widgets.component.scss rename to src/app/iot/index/icon-widgets/icon-widgets.component.scss diff --git a/src/app/components/index/icon-widgets/icon-widgets.component.ts b/src/app/iot/index/icon-widgets/icon-widgets.component.ts similarity index 100% rename from src/app/components/index/icon-widgets/icon-widgets.component.ts rename to src/app/iot/index/icon-widgets/icon-widgets.component.ts diff --git a/src/app/components/index/index.component.html b/src/app/iot/index/index.component.html similarity index 100% rename from src/app/components/index/index.component.html rename to src/app/iot/index/index.component.html diff --git a/src/app/components/index/index.component.scss b/src/app/iot/index/index.component.scss similarity index 100% rename from src/app/components/index/index.component.scss rename to src/app/iot/index/index.component.scss diff --git a/src/app/components/index/index.component.ts b/src/app/iot/index/index.component.ts similarity index 62% rename from src/app/components/index/index.component.ts rename to src/app/iot/index/index.component.ts index 60e24baf..e133e4de 100644 --- a/src/app/components/index/index.component.ts +++ b/src/app/iot/index/index.component.ts @@ -1,9 +1,11 @@ -import { Component, OnInit, ApplicationRef } from '@angular/core'; +import { Component, OnInit, ApplicationRef, AfterContentInit } from '@angular/core'; import { Store } from '@ngrx/store'; -import { AppState, CloudDevice } from '@app/definitions'; +import { CloudDevice } from '@app/definitions'; import { values } from '@lodash'; import { DailyStatistics } from '../../../mocks/dailyStatistics'; import { HistoryStatistics } from '../../../mocks/historyStatistics'; +import { IotModuleState } from '@app/iot/iot.module.defs'; +import { IotRequestsService } from '@app/iot/iot-requests.service'; @Component({ @@ -12,21 +14,27 @@ import { HistoryStatistics } from '../../../mocks/historyStatistics'; styleUrls: ['./index.component.scss'] }) -export class IndexComponent implements OnInit { +export class IndexComponent implements OnInit, AfterContentInit { public hs = HistoryStatistics; public ds = DailyStatistics; public liveData: any; public devices: Array = []; constructor( - private store: Store, + private store: Store, private ref: ApplicationRef, + private requests: IotRequestsService ) { } ngOnInit () { - this.store.select('devices').subscribe((devices) => { + this.store.select('iotModule').subscribe(({devices}) => { this.devices = devices.concat([]); }); } + ngAfterContentInit() { + this.requests.getDevices(); + // this.requests.getLocations(); + // this.requests.getUnconnected(); + } public TempWidget (device: CloudDevice) { return [{ icon: 'icon icon-temperature-2', diff --git a/src/app/iot/iot-common.service.ts b/src/app/iot/iot-common.service.ts new file mode 100644 index 00000000..b5e8d524 --- /dev/null +++ b/src/app/iot/iot-common.service.ts @@ -0,0 +1,19 @@ +import { Injectable } from '@angular/core'; +import { ToasterService } from 'angular2-toaster'; + +@Injectable() +export class IotCommonService { + + constructor( + private toasterService: ToasterService, + ) { } + + + public failPosting() { + this.toasterService.pop('warning', 'Cannot save user.'); + } + public successPosting() { + this.toasterService.pop('success', 'User has been saved.'); + } + +} diff --git a/src/app/iot/iot-mock.interceptor.ts b/src/app/iot/iot-mock.interceptor.ts new file mode 100644 index 00000000..933e061c --- /dev/null +++ b/src/app/iot/iot-mock.interceptor.ts @@ -0,0 +1,22 @@ +import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http'; +import { Observable } from 'rxjs/Observable'; +import 'rxjs/add/operator/do'; +import { Injectable } from '@angular/core'; +import { environment } from '../../environments/environment'; +import { IotMockService } from './iot-mocks.service'; + +@Injectable() +export class IotMockInterceptor implements HttpInterceptor { + constructor( + private mock: IotMockService + ) { + } + + intercept( req: HttpRequest, next: HttpHandler ): Observable> { + if ( environment.targetAPI === false && this.mock.urlMatch( req.url, req.method, this.mock.routes, environment.api ) ) { + return this.mock.handleRoute( req, this.mock.routes, environment.api); + } else { + return next.handle( req ); + } + } +} diff --git a/src/app/iot/iot-mocks.service.ts b/src/app/iot/iot-mocks.service.ts new file mode 100644 index 00000000..08d6d9b0 --- /dev/null +++ b/src/app/iot/iot-mocks.service.ts @@ -0,0 +1,263 @@ +import { Injectable } from '@angular/core'; +import { HttpRequest } from '@angular/common/http'; +import { IResponse, IResponseErrorItem } from 'response-type'; +import { ILocation, CloudDevice, ICloudDeviceDailyHistory, DataSource } from '@app/definitions'; +import { random, times } from '@lodash'; +import { TranslateService } from '@ngx-translate/core'; +import 'rxjs/add/operator/delay'; +import { handleRoute, urlMatch } from '@app/common'; +import { IotSvgService } from '@services/iot-svg/iot-svg.service'; +import { IotDevices } from './iot-mocks'; +const devices = IotDevices; +const validateLocation = (location: ILocation) => { + const errors: Array = []; + if (!location.name) { + errors.push({ + message: 'Please provide a name for location', + location: 'name' + }); + } + if (!location.level) { + errors.push({ + message: 'Please select a level', + location: 'level' + }); + } + if (!location.icon) { + errors.push({ + message: 'Please select an icon for location', + location: 'icon' + }); + } + return errors; +}; + +@Injectable() +export class IotMockService { + + public handleRoute = handleRoute.bind(this); + public urlMatch = urlMatch.bind(this); + public routes = { + 'GET /api/locations': 'getLocations', + 'GET /api/devices/daily-history/:id': 'GetDeviceDailyHistory', + 'GET /api/devices/token': 'getDevicesToken', + 'GET /api/devices/day-history/:date/:id': 'GetDeviceDayHistory', + 'GET /api/device/:id': 'getDevice', + 'GET /api/devices': 'getDevices', + 'GET /api/unconnected': 'getUnconnected', + 'POST /api/device': 'postDevice', + 'POST /api/location': 'postLocation', + 'DELETE /api/location/:id': 'deleteLocation', + 'DELETE /api/device/:id': 'deleteDevice', + }; + + constructor ( + private translate: TranslateService, + ) {} + + public getLocations (): IResponse { + return { + data: { + items: [ + { + id: 1, + name: 'Kitchen', + 'icon': IotSvgService.kitchen, + level: '2', + temperatureDevice: 1 + }, + { + id: 2, + name: 'Bathroom', + 'icon': IotSvgService.pathtub, + level: '3', + temperatureDevice: 2 + }, + { + id: 3, + name: 'Master bedroom', + 'icon': IotSvgService.masterBedroom, + level: '2', + temperatureDevice: 1 + }, + ] + } + }; + } + + public GetDeviceDayHistory(req: HttpRequest): IResponse { + return { + data: { + items: times(24 , () => random (10, 30)), + } + }; + } + + public deleteRole (req: HttpRequest): IResponse { + return { + data: { + items: [ + { + } + ] + } + }; + } + public getUnconnected (req: HttpRequest): IResponse { + return { + data: { + items: [ + { + dataSourceId: 'device-36', + date: new Date(), + value: 22 + } + ] + } + }; + } + public getDevices (): IResponse { + return { + data: { + items: devices + } + }; + } + public getDevice (req: HttpRequest , params): IResponse { + const id = req.url.split('/').reverse()[0]; + return { + data: { + items: devices.filter(device => device.id === +id) + } + }; + } + + public postDevice( req: HttpRequest ): IResponse { + const device: CloudDevice = req.body; + if (! device.id) { + device.id = random(1000, 999999); + } + const validations = DeviceValidator(device); + if (validations.length) { + return { + error: { + message: 'Device cannot be created. Please currect the fields are highlighted', + errors: validations, + code: 34 + } + }; + } + return { + data: { + items: [ + device + ] + } + }; + } + public postLocation(req: HttpRequest): IResponse { + const location: ILocation = req.body; + if ( ! location.id) { + location.id = random(100, 9999); + } + if (validateLocation(location).length) { + return { + error: { + message: 'Cannot create a device. Please fix the following issues', + code: 294, + errors: validateLocation(location) + } + }; + } + return { + data: { + items: [ + { + icon: location.icon, + id: location.id, + name: location.name, + level: location.level, + temperatureDevice: location.temperatureDevice + } + ] + } + }; + } + + public GetDeviceDailyHistory (req: HttpRequest): IResponse { + // const id = req.body.id; + return { + data: { + items: [ + { + date: new Date('2018-09-10'), + average: 33.5 + }, + { + date: new Date('2018-09-09'), + average: 35.2 + }, + { + date: new Date('2018-09-08'), + average: 31.5 + } + ] + } + }; + } + + public getDevicesToken (req: HttpRequest): IResponse { + return { + data: { + items: [ + { + hash: 'ei923040' + } + ] + } + }; + } + public deleteDevice (req: HttpRequest): IResponse { + return { + data: { + items: [ + { + + } + ] + } + }; + } + + public deleteLocation (req: HttpRequest): IResponse { + return { + data: { + items: [ + { + + } + ] + } + }; + } +} + + + +function DeviceValidator (device: CloudDevice) { + const errors: Array = []; + + if ( ! device.name) { + errors.push({ + location: 'name', + message: 'Device must have a name to be identified' + }); + } + if ( ! device.datasource) { + errors.push({ + location: 'datasource', + message: 'You must connect device to a data source' + }); + } + return errors; +} diff --git a/src/app/iot/iot-mocks.ts b/src/app/iot/iot-mocks.ts new file mode 100644 index 00000000..5b9afa69 --- /dev/null +++ b/src/app/iot/iot-mocks.ts @@ -0,0 +1,94 @@ +import { CloudDeviceType } from '@app/definitions'; +import { random } from '@lodash'; + +export const IotDevices = [ + { + id: 1, + name: 'Hall temperature', + type: CloudDeviceType.TemperatureSensor, + datasource: 'device-1', + value: random(10, 30), + location: 1, + preferences: { + DisplayRealTimeTemperatureInSidebar: true, + DisplayHistoryStatisticsInHome: true + } + }, + { + id: 2, + name: 'Kitchen temperature', + type: CloudDeviceType.TemperatureSensor, + datasource: 'device-2', + value: random(10, 30), + location: 1, + preferences: { + DisplayRealTimeTemperatureInSidebar: true + } + }, + { + id: 3, + name: 'Main Lamp', + type: CloudDeviceType.LampBridge, + datasource: 'device-4', + value: 1, + location: 1, + preferences: { + DisplayLampOnOffInHome: true + } + }, + { + id: 4, + name: 'Lobby humidity', + type: CloudDeviceType.HumiditySensor, + datasource: 'device-5', + value: random(10, 60), + location: 2, + preferences: { + DisplayHumidityInHome: true, + } + }, + { + id: 5, + name: 'CO2 sensor', + type: CloudDeviceType.CO2Sensor, + datasource: 'device-6', + value: random(100, 600), + location: 2, + preferences: { + DisplayCO2InHome: true + } + }, + { + id: 6, + name: 'Magnet temperature', + type: CloudDeviceType.TemperatureSensor, + datasource: 'device-7', + value: random(10, 30), + location: 2, + preferences: { + DisplayRealTimeTemperatureInSidebar: true + } + }, + { + id: 7, + name: 'Negative temperature', + type: CloudDeviceType.TemperatureSensor, + datasource: 'device-8', + value: random(10, 30), + location: 3, + preferences: { + DisplayRealTimeTemperatureInSidebar: true + } + }, + { + id: 8, + name: 'Thermal temperature', + type: CloudDeviceType.TemperatureSensor, + datasource: 'device-9', + value: random(10, 30), + location: 3, + preferences: { + DisplayRealTimeTemperatureInSidebar: true + } + }, +]; diff --git a/src/app/iot/iot-module.reducers.ts b/src/app/iot/iot-module.reducers.ts new file mode 100644 index 00000000..1b9ae149 --- /dev/null +++ b/src/app/iot/iot-module.reducers.ts @@ -0,0 +1,12 @@ +import { StoreModule } from '@ngrx/store'; +import { devicesReducer } from './reducers/devices.reducer'; +import { locationsReducer } from './reducers/locations.reducer'; +import { unconnectedReducer } from './reducers/unconnectedSources.reducer'; + +export function iotModuleReducersGenerator () { + return StoreModule.forFeature('iotModule', { + devices: devicesReducer, + locations: locationsReducer, + unconnectedSources: unconnectedReducer, + }); +} diff --git a/src/app/iot/iot-requests.service.ts b/src/app/iot/iot-requests.service.ts new file mode 100644 index 00000000..2d65c373 --- /dev/null +++ b/src/app/iot/iot-requests.service.ts @@ -0,0 +1,221 @@ +import { Injectable } from '@angular/core'; +import { + CloudDevice, + ICloudDeviceDailyHistory, + ILocation + } from '@app/definitions'; +import 'rxjs/add/observable/of'; +import { Store } from '@ngrx/store'; +import { HttpClient } from '@angular/common/http'; +import { environment } from 'environments/environment'; +import { IotMockService } from './iot-mocks.service'; +import { IResponse } from 'response-type'; +import { GetNetworkError, IsSuccessEntity } from '@app/common'; +import 'rxjs/add/operator/toPromise'; +import { IotModuleState } from '@app/iot/iot.module.defs'; +import { random } from '@lodash'; + +declare var io: any; + +@Injectable() +export class IotRequestsService { + constructor( + private mocks: IotMockService, + private store: Store, + private http: HttpClient, + ) { } + + public getLocations() { + this.http.get(environment.api + '/api/locations').subscribe( + (response: any) => { + const collections = response.data.items; + for (const item of collections) { + this.store.dispatch({ + type: 'UPDATE_LOCATION', + payload: item + }); + } + }, + (response) => { + } + ); + } + public getUnconnected () { + this.http.get(environment.api + '/api/unconnected').subscribe( + (response: any) => { + const collections = response.data.items; + for (const item of collections) { + this.store.dispatch({ + type: 'UPDATE_UNCONNECTED_DATA_SOURCE', + payload: item + }); + } + }, + (response: any) => { + }, + ); + } + + public async getDevice (id: number) { + try { + const response: IResponse = await (this.http.get(environment.api + '/api/device/' + id).toPromise()); + const collections = response.data.items; + for (const item of collections) { + this.store.dispatch({ + type: 'UPDATE_DEVICE', + payload: item + }); + } + return collections[0]; + } catch (error) { + + } + } + public getDevices () { + this.http.get(environment.api + '/api/devices').subscribe( + (response: any) => { + const collections = response.data.items; + for (const item of collections) { + this.store.dispatch({ + type: 'UPDATE_DEVICE', + payload: item + }); + } + }, + (response: any) => { + }, + ); + } + + public async GetDeviceDayHistory(id: number, date: Date): Promise> { + const url = environment.api + '/api/devices/day-history/' + date + '/' + id; + const ref = this.http.get(url).toPromise(); + try { + const response: IResponse = await ref; + return response; + } catch (error) { + if (error.name === 'HttpErrorResponse') { + return GetNetworkError(); + } + return error; + } + } + + public async getDeviceDailyHisotry (id: number): Promise> { + const url = environment.api + '/api/devices/daily-history/' + id; + const ref = this.http.get(url).toPromise(); + try { + const response: IResponse = await ref; + return response; + } catch (error) { + if (error.name === 'HttpErrorResponse') { + return GetNetworkError(); + } + return error; + } + } + + + public async PostDevice (device: CloudDevice): Promise> { + const ref = this.http.post(environment.api + '/api/device' , device).toPromise(); + try { + const response: IResponse = await ref; + if (response && response.data && response.data.items && response.data.items[0]) { + const $device = response.data.items[0]; + if ($device) { + this.store.dispatch({ + type: 'UPDATE_DEVICE', + payload: $device + }); + this.store.dispatch({ + type: 'CLEAR_UNCONNECTED_SOURCE', + payload: $device.datasource + }); + } + } + return response; + } catch (error) { + if (error.name === 'HttpErrorResponse') { + return GetNetworkError(); + } + return error; + } + } + + public async PostLocation (location: ILocation): Promise> { + const ref = this.http.post(environment.api + '/api/location' , location).toPromise(); + try { + const response: IResponse = await ref; + if (IsSuccessEntity(response)) { + const $location = response.data.items[0]; + if (! $location.id) { + $location.id = random(1000, 999999); + } + if ($location) { + this.store.dispatch({ + type: 'UPDATE_LOCATION', + payload: $location + }); + } + } + return response; + } catch (error) { + if (error.name === 'HttpErrorResponse') { + return GetNetworkError(); + } + return error; + } + } + async deleteLocation (id: number ) { + const ref = this.http.delete(environment.api + '/api/location/' + id).toPromise(); + try { + const response: IResponse = await ref; + if (IsSuccessEntity(response)) { + const $location = response.data.items[0]; + if (! $location.id) { + $location.id = random(1000, 999999); + } + if ($location) { + this.store.dispatch({ + type: 'DELETE_LOCATION', + payload: id + }); + } + } + return response; + } catch (error) { + if (error.name === 'HttpErrorResponse') { + return GetNetworkError(); + } + return error; + } + } + async deleteDevice (id: number ) { + const ref = this.http.delete(environment.api + '/api/device/' + id).toPromise(); + try { + const response: IResponse = await ref; + if (IsSuccessEntity(response)) { + const $location = response.data.items[0]; + if (! $location.id) { + $location.id = random(1000, 999999); + } + if ($location) { + this.store.dispatch({ + type: 'DELETE_DEVICE', + payload: id + }); + } + } + return response; + } catch (error) { + if (error.name === 'HttpErrorResponse') { + return GetNetworkError(); + } + return error; + } + } + async getDeviceToken (): Promise> { + return await this.http.get(environment.api + '/api/devices/token').toPromise(); + } + +} diff --git a/src/app/iot/iot-routes.ts b/src/app/iot/iot-routes.ts new file mode 100644 index 00000000..ee3b3ac0 --- /dev/null +++ b/src/app/iot/iot-routes.ts @@ -0,0 +1,41 @@ +import { Route } from '@angular/router'; +import { AuthGuard } from '@services/user.service'; +import { IndexComponent } from '@app/iot/index/index.component'; +import { LocationsComponent } from '@app/iot/locations/locations.component'; +import { DevicesComponent } from '@app/iot/devices/devices.component'; +import { ActivityComponent } from '@app/iot/activity/activity.component'; +import { LocationSingleComponent } from '@app/iot/locations/location-single/location-single.component'; +import { DeviceSingleComponent } from '@app/iot/device-single/device-single.component'; +import { DocsComponent } from '@app/iot/docs/docs.component'; +import { ExperimentalComponent } from '@app/iot/experimental/experimental.component'; +import { SendingInformationHttpsComponent } from '@app/iot/docs/sending-information-https/sending-information-https.component'; +import { DeviceEventsActionsComponent } from '@app/iot/device-events-actions/device-events-actions.component'; +import { GpsComponent } from '@app/iot/gps/gps.component'; +import { RestfulComponent } from '@app/iot/docs/restful/restful.component'; + +export function AuthLayoutChild(component: any, route: string, options: any = {}): Route { + return { + path: route, + component: component, + ... options, + canActivate: [AuthGuard], + }; +} + +export const IotAuthLayoutRoutes = [ + AuthLayoutChild (IndexComponent, 'index'), + AuthLayoutChild (LocationsComponent, 'locations'), + AuthLayoutChild (LocationSingleComponent, 'locations/edit/:id', {data: {mode: 'edit'}}), + AuthLayoutChild (LocationSingleComponent, 'location/new', {data: {mode: 'new'}}), + AuthLayoutChild (ActivityComponent, 'activities'), + AuthLayoutChild (GpsComponent, 'gps'), + AuthLayoutChild (DevicesComponent, 'devices'), + AuthLayoutChild (DeviceSingleComponent, 'device/create'), + AuthLayoutChild (DeviceEventsActionsComponent, 'device/events-and-actions/:id'), + AuthLayoutChild (DeviceSingleComponent, 'device/:id'), + AuthLayoutChild (ExperimentalComponent, 'experimental'), + AuthLayoutChild (DeviceSingleComponent, 'create-device-from-source/:sourceId'), + AuthLayoutChild (DocsComponent, 'docs'), + AuthLayoutChild (SendingInformationHttpsComponent, 'docs/sending-information-over-https'), + AuthLayoutChild (RestfulComponent, 'docs/restful-api'), +]; diff --git a/src/app/iot/iot.module.defs.ts b/src/app/iot/iot.module.defs.ts new file mode 100644 index 00000000..c90d9b01 --- /dev/null +++ b/src/app/iot/iot.module.defs.ts @@ -0,0 +1,9 @@ +import { CloudDevice, DataSource } from '@app/definitions'; + +export interface IotModuleState { + iotModule: { + devices: Array; + locations: Array; + unconnectedSources: Array; + }; +} diff --git a/src/app/iot/iot.module.ts b/src/app/iot/iot.module.ts new file mode 100644 index 00000000..4afef171 --- /dev/null +++ b/src/app/iot/iot.module.ts @@ -0,0 +1,248 @@ +import { NgModule, } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { NgUikitModule } from '@app/ng-uikit/ng-uikit.module'; +import { TranslateModule } from '@ngx-translate/core'; +import { RouterModule } from '@angular/router'; +import { NgxTooltipModule } from '../components/ngx-tooltip/ngx-tooltip.module'; +import { NgbModule, NgbModalModule } from '@ng-bootstrap/ng-bootstrap'; +import { ReactiveFormsModule, FormsModule } from '@angular/forms'; +import { HTTP_INTERCEPTORS } from '@angular/common/http'; +import { environment } from 'environments/environment'; +import { IotRequestsService } from '@app/iot/iot-requests.service'; +import { iotModuleReducersGenerator } from '@app/iot/iot-module.reducers'; +import { IotCommonService } from '@app/iot/iot-common.service'; +import { IotMockService } from '@app/iot/iot-mocks.service'; +import { IotMockInterceptor } from '@app/iot/iot-mock.interceptor'; +import { DevicesComponent } from '@app/iot/devices/devices.component'; +import { ActivityWidgetComponent } from '@app/iot/activity/activity-widget/activity-widget.component'; +import { LocationsComponent } from '@app/iot/locations/locations.component'; +import { ActivityComponent } from '@app/iot/activity/activity.component'; +import { LocationRowComponent } from '@app/iot/locations/location-row/location-row.component'; +import { LocationSingleComponent } from '@app/iot/locations/location-single/location-single.component'; +import { SwitchWidgetsComponent } from '@app/iot/switch-widgets/switch-widgets.component'; +import { PlacesComponent } from '@app/iot/places/places.component'; +import { DeviceSingleComponent } from '@app/iot/device-single/device-single.component'; +import { DocsComponent } from '@app/iot/docs/docs.component'; +import { DocsApiWorkaroundComponent } from '@app/iot/docs/docs-api-workaround/docs-api-workaround.component'; +import { DeviceGeneralInformationComponent } from '@app/iot/device-general-information/device-general-information.component'; +import { DeviceTemperatureComponent } from '@app/iot/device-temperature/device-temperature.component'; +import { DeviceLampComponent } from '@app/iot/device-lamp/device-lamp.component'; +import { DeviceCO2Component } from '@app/iot/device-co2/device-co2.component'; +import { DeviceHumidityComponent } from '@app/iot/device-humidity/device-humidity.component'; +import { ActivitiesComponent } from '@app/iot/widgets/activities/activities.component'; +import { HistoryStatisticsComponent } from '@app/iot/widgets/history-statistics/history-statistics.component'; +import { DailyStatisticsComponent } from '@app/iot/widgets/daily-statistics/daily-statistics.component'; +import { SendingInformationHttpsComponent } from '@app/iot/docs/sending-information-https/sending-information-https.component'; +import { DeviceEventsActionsComponent } from '@app/iot/device-events-actions/device-events-actions.component'; +import { ExperimentalComponent } from '@app/iot/experimental/experimental.component'; +import { GpsComponent } from '@app/iot/gps/gps.component'; +import { D3neComponent } from '@app/iot/d3ne/d3ne.component'; +import { LampCardComponent } from '@app/iot/widgets/lamp-card//lamp-card.component'; +import { HumidityComponent } from '@app/iot/widgets/humidity/humidity.component'; +import { CO2WidgetComponent } from '@app/iot/widgets/co2-widget/co2-widget.component'; +import { RestfulComponent } from '@app/iot/docs/restful/restful.component'; +import { WaterBubbleComponent } from '@app/iot/water-bubble/water-bubble.component'; +import { Co2Component } from '@app/iot/co2/co2.component'; +import { IfExperimentalComponent } from '@app/components/if-experimental/if-experimental.component'; +import { NgMediaModule } from '@app/ng-media'; +import { IfNotEnglishComponent } from '@app/iot/if-not-english/if-not-english.component'; +import { RealtimeDocumentModule } from 'realtime-document'; +import { IconWidgetsComponent } from '@app/iot/index/icon-widgets/icon-widgets.component'; +import { IndexComponent } from '@app/iot/index/index.component'; +import { StatisticsComponent } from '@app/iot/statistics/statistics.component'; +import { RealtimeService } from '@app/iot/realtime.service'; + +@NgModule({ + imports: [ + CommonModule, + NgUikitModule, + RouterModule.forChild([]), + TranslateModule.forRoot(), + NgxTooltipModule, + ReactiveFormsModule, + FormsModule, + NgbModule.forRoot(), + NgbModalModule.forRoot(), + iotModuleReducersGenerator(), + NgMediaModule, + RealtimeDocumentModule, + ], + providers: [ + IotCommonService, + IotMockService, + RealtimeService, + IotRequestsService, + !environment.targetAPI ? { provide: HTTP_INTERCEPTORS, useClass: IotMockInterceptor, multi: true } : [], + ], + declarations: [ + StatisticsComponent, + IndexComponent, + IconWidgetsComponent, + IfNotEnglishComponent, + ExperimentalComponent, + DocsApiWorkaroundComponent, + DeviceSingleComponent, + DailyStatisticsComponent, + DevicesComponent, + LampCardComponent, + HumidityComponent, + ActivityWidgetComponent, + LocationsComponent, + ActivityComponent, + DeviceGeneralInformationComponent, + LocationRowComponent, + LocationSingleComponent, + DeviceTemperatureComponent, + DeviceLampComponent, + DeviceCO2Component, + DeviceHumidityComponent, + SwitchWidgetsComponent, + PlacesComponent, + DocsComponent, + DevicesComponent, + CO2WidgetComponent, + LocationsComponent, + ActivitiesComponent, + HistoryStatisticsComponent, + SendingInformationHttpsComponent, + DeviceEventsActionsComponent, + GpsComponent, + D3neComponent, + RestfulComponent, + WaterBubbleComponent, + Co2Component, + IfExperimentalComponent, + ] +}) +export class IotModule { + constructor( + private realtime: RealtimeService, + ) { + this.realtime.ActivateRealtime(); + } +} + +export const DefaultIotModuleNavigation = [ + { + icon: 'icon-devices_other', + title: 'Devices', + permissions: ['DEVICES::VIEW'], + class: 'device', + auth: true, + children: [ + { + link: '/device/create', + icon: '', + title: 'Create a device', + permissions: ['DEVICES::VIEW'], + auth: true, + class: 'device-create' + }, + { + link: '/devices', + icon: '', + title: 'Devices List', + permissions: ['DEVICES::VIEW'], + auth: true, + class: 'device-list', + } + ] + }, + { + icon: 'icon-location_searching', + title: 'Locations', + class: 'location', + children: [ + { + link: '/location/new', + icon: '', + title: 'Create a location', + permissions: ['LOCATIONS::VIEW'], + auth: true, + class: 'location-create' + }, + { + link: '/locations', + icon: '', + title: 'View Locations', + permissions: ['LOCATIONS::VIEW'], + auth: true, + class: 'location-list' + }, + ] + }, + { + icon: 'icon-visibility', + title: 'Monitoring', + class: 'monitoring', + children: [ + { + link: '/monitoring/manage-contacts', + icon: '', + title: 'Manage contacts', + permissions: ['LOCATIONS::VIEW'], + auth: true, + class: 'manage-contacts' + }, + ] + }, + { + title: 'Integration', + icon: 'icon-link', + children: [ + { + link: '/token', + icon: 'icon-settings', + title: 'Access tokens', + class: 'settings', + auth: true + }, + { + // link: '/docs', + icon: 'icon-help', + title: 'documents', + class: 'docs', + children: [ + { + title: 'Introduction', + class: 'docs-introduction', + link: '/docs' + }, + { + title: 'Restful API', + class: 'docs-restful-api', + link: '/docs/restful-api' + }, + { + title: 'Sending information', + class: 'docs-sending-information', + link: '/docs/sending-information-over-https' + }, + + ] + }, + ] + }, + ! environment.production ? { + icon: 'icon-fingerprint', + title: 'Experimental', + class: 'experimental', + children: [ + { + link: '/experimental', + title: 'Introduction', + class: 'introduction', + permissions: ['LOCATIONS::VIEW'], + auth: true, + }, + { + link: '/gps', + icon: '', + title: 'GPS Location', + permissions: ['LOCATIONS::VIEW'], + auth: true, + class: 'gps-location' + }, + ] + } : null, +]; diff --git a/src/app/components/locations/location-row/location-row.component.html b/src/app/iot/locations/location-row/location-row.component.html similarity index 100% rename from src/app/components/locations/location-row/location-row.component.html rename to src/app/iot/locations/location-row/location-row.component.html diff --git a/src/app/components/locations/location-row/location-row.component.scss b/src/app/iot/locations/location-row/location-row.component.scss similarity index 100% rename from src/app/components/locations/location-row/location-row.component.scss rename to src/app/iot/locations/location-row/location-row.component.scss diff --git a/src/app/components/locations/location-row/location-row.component.ts b/src/app/iot/locations/location-row/location-row.component.ts similarity index 89% rename from src/app/components/locations/location-row/location-row.component.ts rename to src/app/iot/locations/location-row/location-row.component.ts index 8fcf2f90..94c16889 100644 --- a/src/app/components/locations/location-row/location-row.component.ts +++ b/src/app/iot/locations/location-row/location-row.component.ts @@ -1,6 +1,7 @@ import { Component, OnInit, Input } from '@angular/core'; -import { ILocation, CloudDevice, AppState } from '@app/definitions'; +import { ILocation, CloudDevice } from '@app/definitions'; import { Store } from '@ngrx/store'; +import { IotModuleState } from '@app/iot/iot.module.defs'; @Component({ selector: 'app-location-row', @@ -17,7 +18,7 @@ export class LocationRowComponent implements OnInit { @Input() public widgets: Array = []; @Input() public location = null; constructor ( - private store: Store, + private store: Store, ) { } @@ -26,7 +27,7 @@ export class LocationRowComponent implements OnInit { * we will display it here. */ public findTemperature (location: ILocation) { - this.store.select('devices').subscribe((devices) => { + this.store.select('iotModule').subscribe(({devices}) => { /* tslint:disable */ const device = devices.find(d => d.id == location.temperatureDevice); if (device) { diff --git a/src/app/components/locations/location-single/location-single.component.html b/src/app/iot/locations/location-single/location-single.component.html similarity index 100% rename from src/app/components/locations/location-single/location-single.component.html rename to src/app/iot/locations/location-single/location-single.component.html diff --git a/src/app/components/locations/location-single/location-single.component.scss b/src/app/iot/locations/location-single/location-single.component.scss similarity index 100% rename from src/app/components/locations/location-single/location-single.component.scss rename to src/app/iot/locations/location-single/location-single.component.scss diff --git a/src/app/components/locations/location-single/location-single.component.ts b/src/app/iot/locations/location-single/location-single.component.ts similarity index 89% rename from src/app/components/locations/location-single/location-single.component.ts rename to src/app/iot/locations/location-single/location-single.component.ts index 45172382..9dada949 100644 --- a/src/app/components/locations/location-single/location-single.component.ts +++ b/src/app/iot/locations/location-single/location-single.component.ts @@ -1,15 +1,16 @@ import { Component, OnInit, ViewChild, AfterContentInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; -import { AppState, ILocation, CloudDevice } from '@app/definitions'; +import { ILocation, CloudDevice } from '@app/definitions'; import { Store } from '@ngrx/store'; import { times } from '@lodash'; import { NgMediaComponent } from '../../../ng-media'; -import { RequestsService } from '@app/services/requests.service'; import { IotImages, IsSuccessEntity, error } from '@app/common'; import { IResponse } from 'response-type'; import { NotificationService } from '@app/services/notification.service'; import { TranslateService } from '@ngx-translate/core'; import { ActionsService } from '@app/services/actions.service'; +import { IotModuleState } from '@app/iot/iot.module.defs'; +import { IotRequestsService } from '@app/iot/iot-requests.service'; @Component({ selector: 'app-location-single', @@ -41,23 +42,23 @@ export class LocationSingleComponent implements OnInit, AfterContentInit { extractRouterInfo () { this.route.params.subscribe(params => { this.form.id = +params['id']; - this.store.select('locations').subscribe((locations: Array) => { + this.store.select('iotModule').subscribe(({locations}) => { const form = locations.find(x => x.id === this.form.id); if ( form ) { this.form = form; } }).unsubscribe(); }).unsubscribe(); - this.store.select('devices').subscribe((devices: Array) => { + this.store.select('iotModule').subscribe(({devices}) => { this.devices = DevicesAsKeyName(devices); }).unsubscribe(); } constructor( private route: ActivatedRoute, - private store: Store, + private store: Store, private router: Router, - private requests: RequestsService, + private requests: IotRequestsService, private actions: ActionsService, private notification: NotificationService, private translation: TranslateService, diff --git a/src/app/components/locations/locations.component.html b/src/app/iot/locations/locations.component.html similarity index 100% rename from src/app/components/locations/locations.component.html rename to src/app/iot/locations/locations.component.html diff --git a/src/app/components/locations/locations.component.scss b/src/app/iot/locations/locations.component.scss similarity index 100% rename from src/app/components/locations/locations.component.scss rename to src/app/iot/locations/locations.component.scss diff --git a/src/app/components/locations/locations.component.ts b/src/app/iot/locations/locations.component.ts similarity index 69% rename from src/app/components/locations/locations.component.ts rename to src/app/iot/locations/locations.component.ts index ca5497a3..d03b8d2e 100644 --- a/src/app/components/locations/locations.component.ts +++ b/src/app/iot/locations/locations.component.ts @@ -1,11 +1,12 @@ import { Component, OnInit, ChangeDetectorRef } from '@angular/core'; -import { AppState, ILocation, CloudDevice } from '@app/definitions'; +import { ILocation, CloudDevice } from '@app/definitions'; import { Store } from '@ngrx/store'; import { ActionsService } from '@services/actions.service'; -import { RequestsService } from '@app/services/requests.service'; import { Router } from '@angular/router'; import { ToasterService } from 'angular2-toaster'; import { NotificationService } from '@app/services/notification.service'; +import { IotModuleState } from '@app/iot/iot.module.defs'; +import { IotRequestsService } from '@app/iot/iot-requests.service'; @Component({ selector: 'app-locations', @@ -19,12 +20,12 @@ export class LocationsComponent implements OnInit { constructor ( public chRef: ChangeDetectorRef, - private store: Store, + private store: Store, public actions: ActionsService, - private requests: RequestsService, private router: Router, private toasterService: ToasterService, private notification: NotificationService, + private requests: IotRequestsService, ) { this.toasterService = toasterService; } @@ -32,12 +33,13 @@ export class LocationsComponent implements OnInit { } ngOnInit() { - this.store.select('locations').subscribe(collection => { - this.locations = (collection as Array); + this.store.select('iotModule').subscribe(({locations}) => { + this.locations = locations; }); - this.store.select('devices').subscribe(collection => { - this.devices = (collection as Array); + this.store.select('iotModule').subscribe(({devices}) => { + this.devices = devices; }); + this.requests.getLocations(); } public DeleteLocation (id: number) { diff --git a/src/app/components/index/places/places.component.html b/src/app/iot/places/places.component.html similarity index 100% rename from src/app/components/index/places/places.component.html rename to src/app/iot/places/places.component.html diff --git a/src/app/components/index/places/places.component.scss b/src/app/iot/places/places.component.scss similarity index 100% rename from src/app/components/index/places/places.component.scss rename to src/app/iot/places/places.component.scss diff --git a/src/app/components/index/places/places.component.ts b/src/app/iot/places/places.component.ts similarity index 64% rename from src/app/components/index/places/places.component.ts rename to src/app/iot/places/places.component.ts index 90cc131e..0dd7c22f 100644 --- a/src/app/components/index/places/places.component.ts +++ b/src/app/iot/places/places.component.ts @@ -1,13 +1,14 @@ import { Component, OnInit, OnDestroy } from '@angular/core'; -import { ILocation, AppState, CloudDevice } from '@app/definitions'; +import { ILocation, CloudDevice } from '@app/definitions'; import { ChangeDetectorRef } from '@angular/core'; import { Store } from '@ngrx/store'; import { ActionsService } from '@services/actions.service'; +import { IotModuleState } from '@app/iot/iot.module.defs'; @Component({ selector: 'app-places', templateUrl: './places.component.html', - styleUrls: ['./places.component.scss', '../../checkbox-switch.scss'] + styleUrls: ['./places.component.scss', '../checkbox-switch.scss'] }) export class PlacesComponent implements OnInit, OnDestroy { @@ -16,18 +17,18 @@ export class PlacesComponent implements OnInit, OnDestroy { constructor( public chRef: ChangeDetectorRef, - private store: Store, + private store: Store, public actions: ActionsService, ) { // Initialize the private variables } async ngOnInit() { - this.store.select('locations').subscribe((locations: Array) => { + this.store.select('iotModule').subscribe(({locations}) => { this.locations = locations; }); - this.store.select('devices').subscribe(collection => { - this.devices = (collection as Array); + this.store.select('iotModule').subscribe(({devices}) => { + this.devices = devices; }); } diff --git a/src/app/services/realtime.service.ts b/src/app/iot/realtime.service.ts similarity index 89% rename from src/app/services/realtime.service.ts rename to src/app/iot/realtime.service.ts index 459a6c76..a6e18aa3 100644 --- a/src/app/services/realtime.service.ts +++ b/src/app/iot/realtime.service.ts @@ -1,10 +1,11 @@ import { Injectable, ApplicationRef } from '@angular/core'; import { Store } from '@ngrx/store'; -import { AppState, CloudDevice, DataSource } from '@app/definitions'; +import { CloudDevice, DataSource } from '@app/definitions'; import { random, isNumber } from '@lodash'; import { environment } from 'environments/environment'; import { IsDataSource } from '@app/common'; import { NotificationService } from '@app/services/notification.service'; +import { IotModuleState } from '@app/iot/iot.module.defs'; declare var Pusher: any; @@ -24,12 +25,11 @@ export class RealtimeService { public devices: Array = []; public unconnectedDevices: Array = []; constructor( - private store: Store, + private store: Store, private ref: ApplicationRef, private notification: NotificationService, ) { - - this.store.select('devices').subscribe((devices) => { + this.store.select('iotModule').subscribe(({devices}) => { this.devices = devices; }); } @@ -124,5 +124,10 @@ export class RealtimeService { }; this.RecieveDataSourceIncoming(data); } - } +// setTimeout(( ) => { +// if (environment.production) { +// this.realtime.connectToRoom(this.user.GetToken()); +// } +// this.isRequesting = false; +// }, 500); diff --git a/src/app/data-layer/devices.reducer.ts b/src/app/iot/reducers/devices.reducer.ts similarity index 100% rename from src/app/data-layer/devices.reducer.ts rename to src/app/iot/reducers/devices.reducer.ts diff --git a/src/app/data-layer/locations.reducer.ts b/src/app/iot/reducers/locations.reducer.ts similarity index 100% rename from src/app/data-layer/locations.reducer.ts rename to src/app/iot/reducers/locations.reducer.ts diff --git a/src/app/data-layer/unconnectedSources.reducer.ts b/src/app/iot/reducers/unconnectedSources.reducer.ts similarity index 100% rename from src/app/data-layer/unconnectedSources.reducer.ts rename to src/app/iot/reducers/unconnectedSources.reducer.ts diff --git a/src/app/components/statistics/statistics.component.html b/src/app/iot/statistics/statistics.component.html similarity index 100% rename from src/app/components/statistics/statistics.component.html rename to src/app/iot/statistics/statistics.component.html diff --git a/src/app/components/statistics/statistics.component.scss b/src/app/iot/statistics/statistics.component.scss similarity index 100% rename from src/app/components/statistics/statistics.component.scss rename to src/app/iot/statistics/statistics.component.scss diff --git a/src/app/components/statistics/statistics.component.ts b/src/app/iot/statistics/statistics.component.ts similarity index 76% rename from src/app/components/statistics/statistics.component.ts rename to src/app/iot/statistics/statistics.component.ts index 19fc6f91..34a8a391 100644 --- a/src/app/components/statistics/statistics.component.ts +++ b/src/app/iot/statistics/statistics.component.ts @@ -1,9 +1,10 @@ import { Component, OnInit, Input, OnDestroy } from '@angular/core'; import { Store } from '@ngrx/store'; -import { AppState, CloudDeviceType } from '@app/definitions'; +import { CloudDeviceType } from '@app/definitions'; import { Observable } from 'rxjs/Observable'; import 'rxjs/add/observable/combineLatest'; import { Subscription } from 'rxjs/Subscription'; +import { IotModuleState } from '@app/iot/iot.module.defs'; @Component({ selector: 'app-statistics', @@ -15,7 +16,7 @@ export class StatisticsComponent implements OnInit, OnDestroy { private ref: Subscription = null; @Input('statistics') public statistics: Array<{title: string, value: any}> = []; constructor( - private store: Store, + private store: Store, ) { } ngOnInit() { @@ -27,21 +28,20 @@ export class StatisticsComponent implements OnInit, OnDestroy { return; } this.ref = Observable.combineLatest( - this.store.select('locations'), - this.store.select('devices'), + this.store.select('iotModule'), ).subscribe((sink) => { this.statistics = []; this.statistics.push({ title: 'Devices', - value: sink[1].length + value: sink[0].devices.length }); this.statistics.push({ title: 'Locations', - value: sink[0].length + value: sink[0].locations.length }); this.statistics.push({ title: 'Temperatures', - value: sink[1].filter(x => +x.type === CloudDeviceType.TemperatureSensor).length + value: sink[0].devices.filter(x => +x.type === CloudDeviceType.TemperatureSensor).length }); this.statistics.push({ title: 'Lights', diff --git a/src/app/components/switch-widgets/switch-widgets.component.html b/src/app/iot/switch-widgets/switch-widgets.component.html similarity index 100% rename from src/app/components/switch-widgets/switch-widgets.component.html rename to src/app/iot/switch-widgets/switch-widgets.component.html diff --git a/src/app/components/switch-widgets/switch-widgets.component.scss b/src/app/iot/switch-widgets/switch-widgets.component.scss similarity index 100% rename from src/app/components/switch-widgets/switch-widgets.component.scss rename to src/app/iot/switch-widgets/switch-widgets.component.scss diff --git a/src/app/components/switch-widgets/switch-widgets.component.ts b/src/app/iot/switch-widgets/switch-widgets.component.ts similarity index 100% rename from src/app/components/switch-widgets/switch-widgets.component.ts rename to src/app/iot/switch-widgets/switch-widgets.component.ts diff --git a/src/app/components/water-bubble/water-bubble.component.html b/src/app/iot/water-bubble/water-bubble.component.html similarity index 100% rename from src/app/components/water-bubble/water-bubble.component.html rename to src/app/iot/water-bubble/water-bubble.component.html diff --git a/src/app/components/water-bubble/water-bubble.component.scss b/src/app/iot/water-bubble/water-bubble.component.scss similarity index 100% rename from src/app/components/water-bubble/water-bubble.component.scss rename to src/app/iot/water-bubble/water-bubble.component.scss diff --git a/src/app/components/water-bubble/water-bubble.component.spec.ts b/src/app/iot/water-bubble/water-bubble.component.spec.ts similarity index 100% rename from src/app/components/water-bubble/water-bubble.component.spec.ts rename to src/app/iot/water-bubble/water-bubble.component.spec.ts diff --git a/src/app/components/water-bubble/water-bubble.component.ts b/src/app/iot/water-bubble/water-bubble.component.ts similarity index 100% rename from src/app/components/water-bubble/water-bubble.component.ts rename to src/app/iot/water-bubble/water-bubble.component.ts diff --git a/src/app/components/widgets/activities/activities.component.html b/src/app/iot/widgets/activities/activities.component.html similarity index 100% rename from src/app/components/widgets/activities/activities.component.html rename to src/app/iot/widgets/activities/activities.component.html diff --git a/src/app/components/widgets/activities/activities.component.scss b/src/app/iot/widgets/activities/activities.component.scss similarity index 100% rename from src/app/components/widgets/activities/activities.component.scss rename to src/app/iot/widgets/activities/activities.component.scss diff --git a/src/app/components/widgets/activities/activities.component.spec.ts b/src/app/iot/widgets/activities/activities.component.spec.ts similarity index 100% rename from src/app/components/widgets/activities/activities.component.spec.ts rename to src/app/iot/widgets/activities/activities.component.spec.ts diff --git a/src/app/components/widgets/activities/activities.component.ts b/src/app/iot/widgets/activities/activities.component.ts similarity index 100% rename from src/app/components/widgets/activities/activities.component.ts rename to src/app/iot/widgets/activities/activities.component.ts diff --git a/src/app/components/widgets/co2-widget/co2-widget.component.html b/src/app/iot/widgets/co2-widget/co2-widget.component.html similarity index 100% rename from src/app/components/widgets/co2-widget/co2-widget.component.html rename to src/app/iot/widgets/co2-widget/co2-widget.component.html diff --git a/src/app/components/widgets/co2-widget/co2-widget.component.scss b/src/app/iot/widgets/co2-widget/co2-widget.component.scss similarity index 100% rename from src/app/components/widgets/co2-widget/co2-widget.component.scss rename to src/app/iot/widgets/co2-widget/co2-widget.component.scss diff --git a/src/app/components/widgets/co2-widget/co2-widget.component.ts b/src/app/iot/widgets/co2-widget/co2-widget.component.ts similarity index 77% rename from src/app/components/widgets/co2-widget/co2-widget.component.ts rename to src/app/iot/widgets/co2-widget/co2-widget.component.ts index 2742ef1f..a74f4ccd 100644 --- a/src/app/components/widgets/co2-widget/co2-widget.component.ts +++ b/src/app/iot/widgets/co2-widget/co2-widget.component.ts @@ -1,7 +1,8 @@ import { Component, OnInit, Input, OnDestroy } from '@angular/core'; declare var Highcharts: any; -import { CloudDevice, AppState } from '@app/definitions'; +import { CloudDevice } from '@app/definitions'; import { Store } from '@ngrx/store'; +import { IotModuleState } from '@app/iot/iot.module.defs'; @Component({ selector: 'app-co2-widget', @@ -21,11 +22,11 @@ export class CO2WidgetComponent implements OnInit, OnDestroy { public average = 0; constructor( - private store: Store + private store: Store ) { } ngOnInit() { - this.ref = this.store.select('devices').subscribe(devices => { + this.ref = this.store.select('iotModule').subscribe(({devices}) => { this.device = devices.find(x => +x.id === +this.id); }); } diff --git a/src/app/components/widgets/daily-statistics/daily-statistics.component.html b/src/app/iot/widgets/daily-statistics/daily-statistics.component.html similarity index 100% rename from src/app/components/widgets/daily-statistics/daily-statistics.component.html rename to src/app/iot/widgets/daily-statistics/daily-statistics.component.html diff --git a/src/app/components/widgets/daily-statistics/daily-statistics.component.scss b/src/app/iot/widgets/daily-statistics/daily-statistics.component.scss similarity index 100% rename from src/app/components/widgets/daily-statistics/daily-statistics.component.scss rename to src/app/iot/widgets/daily-statistics/daily-statistics.component.scss diff --git a/src/app/components/widgets/daily-statistics/daily-statistics.component.spec.ts b/src/app/iot/widgets/daily-statistics/daily-statistics.component.spec.ts similarity index 100% rename from src/app/components/widgets/daily-statistics/daily-statistics.component.spec.ts rename to src/app/iot/widgets/daily-statistics/daily-statistics.component.spec.ts diff --git a/src/app/components/widgets/daily-statistics/daily-statistics.component.ts b/src/app/iot/widgets/daily-statistics/daily-statistics.component.ts similarity index 94% rename from src/app/components/widgets/daily-statistics/daily-statistics.component.ts rename to src/app/iot/widgets/daily-statistics/daily-statistics.component.ts index 855a9e7b..1e69b42b 100644 --- a/src/app/components/widgets/daily-statistics/daily-statistics.component.ts +++ b/src/app/iot/widgets/daily-statistics/daily-statistics.component.ts @@ -1,8 +1,9 @@ import { Component, OnInit, Input, AfterViewInit } from '@angular/core'; declare var Highcharts: any; -import { CloudDevice, DataSource, AppState } from '@app/definitions'; +import { CloudDevice, DataSource } from '@app/definitions'; import { Store } from '@ngrx/store'; import { GlobalizationService } from '@app/services/globalization.service'; +import { IotModuleState } from '@app/iot/iot.module.defs'; function generateMockSeries() { const series = []; @@ -128,10 +129,10 @@ export class DailyStatisticsComponent implements OnInit, AfterViewInit { } constructor( - private store: Store, + private store: Store, private globalization: GlobalizationService ) { - globalization.layoutDirectionEmmiter.subscribe(direction => { + globalization.layoutDirectionEmitter.subscribe(direction => { this.chart.xAxis.reversed = direction === 'ltr' ? false : true; this.drawChart(); }); @@ -150,7 +151,7 @@ export class DailyStatisticsComponent implements OnInit, AfterViewInit { ngOnInit() { this.chartName = 'chart-' + this.id; - this.store.select('devices').subscribe(devices => { + this.store.select('iotModule').subscribe(({devices}) => { this.device = devices.find(x => +x.id === +this.id); const history = this.device && this.device.dataHistory && this.device.dataHistory[this.device.dataHistory.length - 1] || null; diff --git a/src/app/components/widgets/history-statistics/history-statistics.component.html b/src/app/iot/widgets/history-statistics/history-statistics.component.html similarity index 100% rename from src/app/components/widgets/history-statistics/history-statistics.component.html rename to src/app/iot/widgets/history-statistics/history-statistics.component.html diff --git a/src/app/components/widgets/history-statistics/history-statistics.component.scss b/src/app/iot/widgets/history-statistics/history-statistics.component.scss similarity index 100% rename from src/app/components/widgets/history-statistics/history-statistics.component.scss rename to src/app/iot/widgets/history-statistics/history-statistics.component.scss diff --git a/src/app/components/widgets/history-statistics/history-statistics.component.spec.ts b/src/app/iot/widgets/history-statistics/history-statistics.component.spec.ts similarity index 100% rename from src/app/components/widgets/history-statistics/history-statistics.component.spec.ts rename to src/app/iot/widgets/history-statistics/history-statistics.component.spec.ts diff --git a/src/app/components/widgets/history-statistics/history-statistics.component.ts b/src/app/iot/widgets/history-statistics/history-statistics.component.ts similarity index 95% rename from src/app/components/widgets/history-statistics/history-statistics.component.ts rename to src/app/iot/widgets/history-statistics/history-statistics.component.ts index 9cc7d3f2..dc43bb44 100644 --- a/src/app/components/widgets/history-statistics/history-statistics.component.ts +++ b/src/app/iot/widgets/history-statistics/history-statistics.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit, Input } from '@angular/core'; -import { RequestsService } from '@app/services/requests.service'; import { CloudDevice, ICloudDeviceDailyHistory } from '@app/definitions'; import { GlobalizationService } from '@app/services/globalization.service'; +import { IotRequestsService } from '@app/iot/iot-requests.service'; declare var Highcharts: any; interface IComponentHistory extends ICloudDeviceDailyHistory { @@ -94,10 +94,10 @@ export class HistoryStatisticsComponent implements OnInit { } constructor( - private requests: RequestsService, + private requests: IotRequestsService, private globalization: GlobalizationService ) { - globalization.layoutDirectionEmmiter.subscribe(direction => { + globalization.layoutDirectionEmitter.subscribe(direction => { this.drawChart(true); }); } diff --git a/src/app/components/widgets/humidity/humidity.component.html b/src/app/iot/widgets/humidity/humidity.component.html similarity index 100% rename from src/app/components/widgets/humidity/humidity.component.html rename to src/app/iot/widgets/humidity/humidity.component.html diff --git a/src/app/components/widgets/humidity/humidity.component.scss b/src/app/iot/widgets/humidity/humidity.component.scss similarity index 100% rename from src/app/components/widgets/humidity/humidity.component.scss rename to src/app/iot/widgets/humidity/humidity.component.scss diff --git a/src/app/components/widgets/humidity/humidity.component.ts b/src/app/iot/widgets/humidity/humidity.component.ts similarity index 76% rename from src/app/components/widgets/humidity/humidity.component.ts rename to src/app/iot/widgets/humidity/humidity.component.ts index ef9e5e3a..7cb03be4 100644 --- a/src/app/components/widgets/humidity/humidity.component.ts +++ b/src/app/iot/widgets/humidity/humidity.component.ts @@ -1,7 +1,8 @@ import { Component, OnInit, Input, OnDestroy } from '@angular/core'; declare var Highcharts: any; -import { CloudDevice, AppState } from '@app/definitions'; +import { CloudDevice } from '@app/definitions'; import { Store } from '@ngrx/store'; +import { IotModuleState } from '@app/iot/iot.module.defs'; @Component({ selector: 'app-humidity', @@ -21,11 +22,11 @@ export class HumidityComponent implements OnInit, OnDestroy { public average = 0; constructor( - private store: Store + private store: Store ) { } ngOnInit() { - this.ref = this.store.select('devices').subscribe(devices => { + this.ref = this.store.select('iotModule').subscribe(({devices}) => { this.device = devices.find(x => +x.id === +this.id); }); } diff --git a/src/app/components/widgets/lamp-card/lamp-card.component.html b/src/app/iot/widgets/lamp-card/lamp-card.component.html similarity index 100% rename from src/app/components/widgets/lamp-card/lamp-card.component.html rename to src/app/iot/widgets/lamp-card/lamp-card.component.html diff --git a/src/app/components/widgets/lamp-card/lamp-card.component.scss b/src/app/iot/widgets/lamp-card/lamp-card.component.scss similarity index 100% rename from src/app/components/widgets/lamp-card/lamp-card.component.scss rename to src/app/iot/widgets/lamp-card/lamp-card.component.scss diff --git a/src/app/components/widgets/lamp-card/lamp-card.component.ts b/src/app/iot/widgets/lamp-card/lamp-card.component.ts similarity index 95% rename from src/app/components/widgets/lamp-card/lamp-card.component.ts rename to src/app/iot/widgets/lamp-card/lamp-card.component.ts index e99c7845..7b4b1ee8 100644 --- a/src/app/components/widgets/lamp-card/lamp-card.component.ts +++ b/src/app/iot/widgets/lamp-card/lamp-card.component.ts @@ -1,7 +1,8 @@ import { Component, OnInit, Input, AfterViewInit } from '@angular/core'; declare var Highcharts: any; -import { CloudDevice, DataSource, AppState } from '@app/definitions'; +import { CloudDevice, DataSource } from '@app/definitions'; import { Store } from '@ngrx/store'; +import { IotModuleState } from '@app/iot/iot.module.defs'; function generateMockSeries() { const series = []; @@ -123,7 +124,7 @@ export class LampCardComponent implements OnInit, AfterViewInit { } constructor( - private store: Store + private store: Store ) { } public pushValue (date: Date, value: number) { @@ -139,7 +140,7 @@ export class LampCardComponent implements OnInit, AfterViewInit { ngOnInit() { this.chartName = 'chart-' + this.id; - this.store.select('devices').subscribe(devices => { + this.store.select('iotModule').subscribe(({devices}) => { this.device = devices.find(x => +x.id === +this.id); const history = this.device && this.device.dataHistory && this.device.dataHistory[this.device.dataHistory.length - 1] || null; diff --git a/src/app/ng-media/components/image-editor/image-editor.component.ts b/src/app/ng-media/components/image-editor/image-editor.component.ts index 3d859283..e9d4dc40 100644 --- a/src/app/ng-media/components/image-editor/image-editor.component.ts +++ b/src/app/ng-media/components/image-editor/image-editor.component.ts @@ -83,7 +83,6 @@ export class ImageEditorComponent implements OnInit { flipImage(state) { switch (state) { case 'horizontal': - console.log('1'); this.ctx.translate(this.canvas.width, 0); this.ctx.scale(-1, 1); break; diff --git a/src/app/ng-media/services/requests.service.ts b/src/app/ng-media/services/requests.service.ts index 4374de6d..c66480de 100644 --- a/src/app/ng-media/services/requests.service.ts +++ b/src/app/ng-media/services/requests.service.ts @@ -20,7 +20,6 @@ export class RequestsService { } public DeleteItem(id: string) { - console.log('Requested to delete: ', id); this.http.delete('http://localhost:1337/ngmedia/delete/' + id).subscribe( (response) => { console.log(response); diff --git a/src/app/ng-media/services/storage.ts b/src/app/ng-media/services/storage.ts index 83b09cd2..77041f9e 100644 --- a/src/app/ng-media/services/storage.ts +++ b/src/app/ng-media/services/storage.ts @@ -27,9 +27,7 @@ export class Storage { return this.subject.asObservable(); } public DeleteItem(image: IImage) { - console.log('Before delete: ', this.items.length); this.items = this.items.filter(x => x.id !== image.id); - console.log('Before after: ', this.items.length); this.subject.next(this.items); } public UpdateItem(image: IImage) { diff --git a/src/app/ng-uikit/ng-uikit.module.ts b/src/app/ng-uikit/ng-uikit.module.ts index eb79f611..6dc44c03 100644 --- a/src/app/ng-uikit/ng-uikit.module.ts +++ b/src/app/ng-uikit/ng-uikit.module.ts @@ -1,12 +1,13 @@ import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; -import { PageContainerComponent } from '../components/page-container/page-container.component'; +import { PageContainerComponent } from '@app/ng5-basic/page-container/page-container.component'; import { ErrorMessageComponent } from '../components/error-message/error-message.component'; import { TranslateModule, TranslateService } from '@ngx-translate/core'; import { UiIconBoxComponent } from '@app/uikit/ui-icon-box/ui-icon-box.component'; import { UiPanelBoxComponent } from '@app/uikit/ui-panel-box/ui-panel-box.component'; import { UiSmallBoxComponent } from '@app/uikit/ui-small-box/ui-small-box.component'; import { RouterModule } from '@angular/router'; +import { ProgressLineComponent } from '@app/uikit/progress-line/progress-line.component'; @NgModule({ imports: [ @@ -18,12 +19,14 @@ import { RouterModule } from '@angular/router'; PageContainerComponent, ErrorMessageComponent, UiIconBoxComponent, + ProgressLineComponent, UiPanelBoxComponent, UiSmallBoxComponent, ], exports: [ PageContainerComponent, ErrorMessageComponent, + ProgressLineComponent, UiIconBoxComponent, UiPanelBoxComponent, UiSmallBoxComponent, diff --git a/src/app/ng5-basic/layout/layout.component.ts b/src/app/ng5-basic/layout/layout.component.ts index 0fce0872..354da4d7 100644 --- a/src/app/ng5-basic/layout/layout.component.ts +++ b/src/app/ng5-basic/layout/layout.component.ts @@ -1,9 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { SidebarControllerService } from '../ngx-sidebar/sidebar-controller.service'; -import { RealtimeService } from '@app/services/realtime.service'; -import { RequestsService } from '@app/services/requests.service'; import { UserService } from '@app/services/user.service'; -import { environment } from 'environments/environment'; import { ToasterConfig } from 'angular2-toaster'; @Component({ @@ -20,8 +17,7 @@ export class LayoutComponent implements OnInit { }); constructor( public sidebar: SidebarControllerService, - private realtime: RealtimeService, - private requests: RequestsService, + // private realtime: RealtimeService, private user: UserService, ) { this.sidebar.ToggleSidebar.subscribe((e) => { @@ -37,20 +33,9 @@ export class LayoutComponent implements OnInit { } ngOnInit() { - this.isRequesting = true; if (window.innerWidth < 992) { this.sideState = false; } - this.requests.getDevices(); - this.requests.getLocations(); - this.requests.getUnconnected(); - this.requests.GetRoles(); - setTimeout(( ) => { - if (environment.production) { - this.realtime.connectToRoom(this.user.GetToken()); - } - this.isRequesting = false; - }, 500); } sideOff() { diff --git a/src/app/ng5-basic/nav-bar/nav-bar.component.html b/src/app/ng5-basic/nav-bar/nav-bar.component.html index bc7ad001..4a0a4c77 100644 --- a/src/app/ng5-basic/nav-bar/nav-bar.component.html +++ b/src/app/ng5-basic/nav-bar/nav-bar.component.html @@ -19,9 +19,7 @@
- + \ No newline at end of file diff --git a/src/app/ng5-basic/ng5-basic.module.ts b/src/app/ng5-basic/ng5-basic.module.ts index 052288a6..5c40ce8c 100644 --- a/src/app/ng5-basic/ng5-basic.module.ts +++ b/src/app/ng5-basic/ng5-basic.module.ts @@ -4,7 +4,6 @@ import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { RouterModule } from '@angular/router'; import { NgMediaModule } from '../ng-media'; -import { RealtimeService } from '@services/realtime.service'; import { NotificationService } from '@services/notification.service'; import { PermissionsService } from '@services/permissions.service'; import { RequestsService } from '@services/requests.service'; @@ -51,10 +50,8 @@ import { TranslateModule } from '@ngx-translate/core'; ], providers: [ SidebarControllerService, - RealtimeService, PermissionsService, RequestsService, - RealtimeService, MockService, ActionsService, NotificationService, @@ -69,9 +66,4 @@ import { TranslateModule } from '@ngx-translate/core'; }) export class Ng5BasicModule { - constructor ( - private realtime: RealtimeService, - ) { - // Realtime service is imported intentionally - } } diff --git a/src/app/components/page-container/page-container.component.html b/src/app/ng5-basic/page-container/page-container.component.html similarity index 100% rename from src/app/components/page-container/page-container.component.html rename to src/app/ng5-basic/page-container/page-container.component.html diff --git a/src/app/components/page-container/page-container.component.scss b/src/app/ng5-basic/page-container/page-container.component.scss similarity index 100% rename from src/app/components/page-container/page-container.component.scss rename to src/app/ng5-basic/page-container/page-container.component.scss diff --git a/src/app/components/page-container/page-container.component.spec.ts b/src/app/ng5-basic/page-container/page-container.component.spec.ts similarity index 100% rename from src/app/components/page-container/page-container.component.spec.ts rename to src/app/ng5-basic/page-container/page-container.component.spec.ts diff --git a/src/app/components/page-container/page-container.component.ts b/src/app/ng5-basic/page-container/page-container.component.ts similarity index 100% rename from src/app/components/page-container/page-container.component.ts rename to src/app/ng5-basic/page-container/page-container.component.ts diff --git a/src/app/services/actions.service.ts b/src/app/services/actions.service.ts index 1eeb7dbc..c6f2c717 100644 --- a/src/app/services/actions.service.ts +++ b/src/app/services/actions.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import { CloudDevice, AppState, IActivity, ILocation, IRole } from '@app/definitions'; +import { CloudDevice, AppState, IActivity, ILocation } from '@app/definitions'; import { Store } from '@ngrx/store'; import { TranslateService } from '@ngx-translate/core'; import { RequestsService } from '@app/services/requests.service'; @@ -30,13 +30,6 @@ export class ActionsService { public findWidgets (devices, location: ILocation): Array { return devices.filter(device => +device.location === +location.id); } - public DeleteRole (role: IRole) { - if (confirm( this.translate.get('Are you sure to delete this role?')['value'])) { - this.requests.deleteRole(role.id); - this.notification.InvokeRoleDelete(role); - this.router.navigateByUrl('/roles'); - } - } public scrollTop () { const el = new SimpleBar(document.getElementById('layout')); diff --git a/src/app/services/globalization.service.ts b/src/app/services/globalization.service.ts index ce3bbbec..b85f24c0 100644 --- a/src/app/services/globalization.service.ts +++ b/src/app/services/globalization.service.ts @@ -22,7 +22,7 @@ export const StableLanguages = { export const SupportedLanguages = environment.production ? StableLanguages : merge(StableLanguages, ExperimentalLanguages); @Injectable() export class GlobalizationService { - public layoutDirectionEmmiter: EventEmitter = new EventEmitter(); + public layoutDirectionEmitter: EventEmitter = new EventEmitter(); public layoutDirection: string; constructor( @Inject(DOCUMENT) private document: Document, @@ -54,7 +54,7 @@ export class GlobalizationService { localSetter() { const lang: string = this.translate.currentLang; const direction = SupportedLanguages[lang].direction; - this.layoutDirectionEmmiter.emit(direction); + this.layoutDirectionEmitter.emit(direction); this.layoutDirection = direction; } diff --git a/src/app/services/mocks.service.ts b/src/app/services/mocks.service.ts index 0db21dff..4851a60c 100644 --- a/src/app/services/mocks.service.ts +++ b/src/app/services/mocks.service.ts @@ -5,147 +5,18 @@ import { IResponse, IResponseErrorItem } from 'response-type'; import { matchPattern } from 'url-matcher'; import { environment } from '../../environments/environment'; import { PermissionsService } from '@services/permissions.service'; -import { IUserForm, CloudDevice, DataSource, IUser, ICloudDeviceDailyHistory, IContact, IResetForm, IRole } from '@app/definitions'; -import { CloudDeviceType } from '@app/definitions'; +import { IUserForm, IUser, IContact, IResetForm } from '@app/definitions'; import { IotSvgService } from '@services/iot-svg/iot-svg.service'; import { random, times } from '@lodash'; -import { ILocation } from '@app/definitions'; import { TranslateService } from '@ngx-translate/core'; import 'rxjs/add/operator/delay'; -const devices = [ - { - id: 1, - name: 'Hall temperature', - type: CloudDeviceType.TemperatureSensor, - datasource: 'device-1', - value: random(10, 30), - location: 1, - preferences: { - DisplayRealTimeTemperatureInSidebar: true, - DisplayHistoryStatisticsInHome: true - } - }, - { - id: 2, - name: 'Kitchen temperature', - type: CloudDeviceType.TemperatureSensor, - datasource: 'device-2', - value: random(10, 30), - location: 1, - preferences: { - DisplayRealTimeTemperatureInSidebar: true - } - }, - { - id: 3, - name: 'Main Lamp', - type: CloudDeviceType.LampBridge, - datasource: 'device-4', - value: 1, - location: 1, - preferences: { - DisplayLampOnOffInHome: true - } - }, - { - id: 4, - name: 'Lobby humidity', - type: CloudDeviceType.HumiditySensor, - datasource: 'device-5', - value: random(10, 60), - location: 2, - preferences: { - DisplayHumidityInHome: true, - } - }, - { - id: 5, - name: 'CO2 sensor', - type: CloudDeviceType.CO2Sensor, - datasource: 'device-6', - value: random(100, 600), - location: 2, - preferences: { - DisplayCO2InHome: true - } - }, - { - id: 6, - name: 'Magnet temperature', - type: CloudDeviceType.TemperatureSensor, - datasource: 'device-7', - value: random(10, 30), - location: 2, - preferences: { - DisplayRealTimeTemperatureInSidebar: true - } - }, - { - id: 7, - name: 'Negative temperature', - type: CloudDeviceType.TemperatureSensor, - datasource: 'device-8', - value: random(10, 30), - location: 3, - preferences: { - DisplayRealTimeTemperatureInSidebar: true - } - }, - { - id: 8, - name: 'Thermal temperature', - type: CloudDeviceType.TemperatureSensor, - datasource: 'device-9', - value: random(10, 30), - location: 3, - preferences: { - DisplayRealTimeTemperatureInSidebar: true - } - }, -]; -const validateLocation = (location: ILocation) => { - const errors: Array = []; - if (!location.name) { - errors.push({ - message: 'Please provide a name for location', - location: 'name' - }); - } - if (!location.level) { - errors.push({ - message: 'Please select a level', - location: 'level' - }); - } - if (!location.icon) { - errors.push({ - message: 'Please select an icon for location', - location: 'icon' - }); - } - return errors; -}; @Injectable() export class MockService { public routes = { 'POST /api/user/signin': 'signIn', 'POST /api/user/signup': 'signUp', - 'GET /api/locations': 'getLocations', - 'DELETE /api/role/:id': 'deleteRole', - 'GET /api/roles': 'getRoles', - 'POST /api/role': 'postRole', - 'GET /api/devices/daily-history/:id': 'GetDeviceDailyHistory', - 'GET /api/devices/token': 'getDevicesToken', - 'GET /api/devices/day-history/:date/:id': 'GetDeviceDayHistory', - 'GET /api/device/:id': 'getDevice', - 'GET /api/devices': 'getDevices', - 'GET /api/unconnected': 'getUnconnected', - 'POST /api/device': 'postDevice', 'POST /api/forget-password': 'forgetPassword', - 'POST /api/location': 'postLocation', - 'DELETE /api/location/:id': 'deleteLocation', - 'DELETE /api/device/:id': 'deleteDevice', 'GET /api/contact-details': 'GetContactDetails', 'POST /api/user/settings': 'updateUserProfile', 'POST /api/contact-details': 'UpdateContactDetails', @@ -233,13 +104,6 @@ export class MockService { }; } - public GetDeviceDayHistory(req: HttpRequest): IResponse { - return { - data: { - items: times(24 , () => random (10, 30)), - } - }; - } public mockUser () { return { email: 'alitorabi@seekasia.com', @@ -259,16 +123,6 @@ export class MockService { }, }; } - public deleteRole (req: HttpRequest): IResponse { - return { - data: { - items: [ - { - } - ] - } - }; - } signIn( req: HttpRequest ): IResponse { if ( req.body.email === 'test@test.com' && req.body.password === '123321' ) { return { @@ -307,32 +161,6 @@ export class MockService { }; } } - public getUnconnected (req: HttpRequest): IResponse { - return { - data: { - items: [ - { - dataSourceId: 'device-36', - date: new Date(), - value: 22 - } - ] - } - }; - } - public postRole (req: HttpRequest): IResponse { - const form: IRole = req.body; - if (!form.id) { - form.id = random(1, 99999); - } - return { - data: { - items: [ - form - ] - } - }; - } public signUp (req: HttpRequest): IResponse { const form = req.body; function hasUnvalidFields(user: IUserForm): Array { @@ -371,126 +199,7 @@ export class MockService { } }; } - public getRoles (): IResponse { - return { - data: { - items: [ - { - id: 1, - title: 'Developer', - permissions: [] - }, - { - id: 2, - title: 'Master', - permissions: [] - }, - { - id: 3, - title: 'Guest', - permissions: [] - } - ] - } - }; - } - public getDevices (): IResponse { - return { - data: { - items: devices - } - }; - } - public getDevice (req: HttpRequest , params): IResponse { - const id = req.url.split('/').reverse()[0]; - return { - data: { - items: devices.filter(device => device.id === +id) - } - }; - } - - public getLocations (): IResponse { - return { - data: { - items: [ - { - id: 1, - name: 'Kitchen', - 'icon': IotSvgService.kitchen, - level: '2', - temperatureDevice: 1 - }, - { - id: 2, - name: 'Bathroom', - 'icon': IotSvgService.pathtub, - level: '3', - temperatureDevice: 2 - }, - { - id: 3, - name: 'Master bedroom', - 'icon': IotSvgService.masterBedroom, - level: '2', - temperatureDevice: 1 - }, - ] - } - }; - } - public postDevice( req: HttpRequest ): IResponse { - const device: CloudDevice = req.body; - if (! device.id) { - device.id = random(1000, 999999); - } - const validations = DeviceValidator(device); - if (validations.length) { - return { - error: { - message: 'Device cannot be created. Please currect the fields are highlighted', - errors: validations, - code: 34 - } - }; - } - return { - data: { - items: [ - device - ] - } - }; - } - public postLocation(req: HttpRequest): IResponse { - const location: ILocation = req.body; - if ( ! location.id) { - location.id = random(100, 9999); - } - if (validateLocation(location).length) { - return { - error: { - message: 'Cannot create a device. Please fix the following issues', - code: 294, - errors: validateLocation(location) - } - }; - } - return { - data: { - items: [ - { - icon: location.icon, - id: location.id, - name: location.name, - level: location.level, - temperatureDevice: location.temperatureDevice - } - ] - } - }; - } public UpdateContactDetails(req: HttpRequest): IResponse { return { @@ -523,27 +232,6 @@ export class MockService { } }; } - public GetDeviceDailyHistory (req: HttpRequest): IResponse { - // const id = req.body.id; - return { - data: { - items: [ - { - date: new Date('2018-09-10'), - average: 33.5 - }, - { - date: new Date('2018-09-09'), - average: 35.2 - }, - { - date: new Date('2018-09-08'), - average: 31.5 - } - ] - } - }; - } public updateUserProfile(req: HttpRequest): IResponse { const user: IUser = req.body; return { @@ -577,56 +265,4 @@ export class MockService { } }; } - - public deleteLocation (req: HttpRequest): IResponse { - return { - data: { - items: [ - { - - } - ] - } - }; - } - public deleteDevice (req: HttpRequest): IResponse { - return { - data: { - items: [ - { - - } - ] - } - }; - } - - public getDevicesToken (req: HttpRequest): IResponse { - return { - data: { - items: [ - { - hash: 'ei923040' - } - ] - } - }; - } -} -function DeviceValidator (device: CloudDevice) { - const errors: Array = []; - - if ( ! device.name) { - errors.push({ - location: 'name', - message: 'Device must have a name to be identified' - }); - } - if ( ! device.datasource) { - errors.push({ - location: 'datasource', - message: 'You must connect device to a data source' - }); - } - return errors; } diff --git a/src/app/services/requests.service.ts b/src/app/services/requests.service.ts index ade350b4..5406a3e8 100644 --- a/src/app/services/requests.service.ts +++ b/src/app/services/requests.service.ts @@ -1,152 +1,26 @@ import { Injectable } from '@angular/core'; import { - AppState, - CloudDevice, ILocation, IUser, - ICloudDeviceDailyHistory, ISettingsUpdateResponse, - IContact, - IRole + IContact } from '@app/definitions'; -import { PermissionsService } from './permissions.service'; import 'rxjs/add/observable/of'; -import { Store } from '@ngrx/store'; import { HttpClient } from '@angular/common/http'; import { environment } from 'environments/environment'; -import { MockService } from '@app/services/mocks.service'; import { IResponse } from 'response-type'; -import { GetNetworkError, IsSuccessEntity } from '@app/common'; -import { random } from '@lodash'; +import { GetNetworkError } from '@app/common'; import 'rxjs/add/operator/toPromise'; -declare var io: any; - @Injectable() export class RequestsService { constructor( - private permissions: PermissionsService, - private mocks: MockService, - private store: Store, private http: HttpClient, ) { } - getLocations() { - this.http.get(environment.api + '/api/locations').subscribe( - (response: any) => { - const collections = response.data.items; - for (const item of collections) { - this.store.dispatch({ - type: 'UPDATE_LOCATION', - payload: item - }); - } - }, - (response) => { - } - ); - } - - async getDeviceToken (): Promise> { - return await this.http.get(environment.api + '/api/devices/token').toPromise(); - } - - getUnconnected () { - this.http.get(environment.api + '/api/unconnected').subscribe( - (response: any) => { - const collections = response.data.items; - for (const item of collections) { - this.store.dispatch({ - type: 'UPDATE_UNCONNECTED_DATA_SOURCE', - payload: item - }); - } - }, - (response: any) => { - }, - ); - } - - public async getDevice (id: number) { - try { - const response: IResponse = await (this.http.get(environment.api + '/api/device/' + id).toPromise()); - const collections = response.data.items; - for (const item of collections) { - this.store.dispatch({ - type: 'UPDATE_DEVICE', - payload: item - }); - } - return collections[0]; - } catch (error) { - - } - } - getDevices () { - this.http.get(environment.api + '/api/devices').subscribe( - (response: any) => { - const collections = response.data.items; - for (const item of collections) { - this.store.dispatch({ - type: 'UPDATE_DEVICE', - payload: item - }); - } - }, - (response: any) => { - }, - ); - } - public async GetDeviceDayHistory(id: number, date: Date): Promise> { - const url = environment.api + '/api/devices/day-history/' + date + '/' + id; - const ref = this.http.get(url).toPromise(); - try { - const response: IResponse = await ref; - return response; - } catch (error) { - if (error.name === 'HttpErrorResponse') { - return GetNetworkError(); - } - return error; - } - } - - public async getDeviceDailyHisotry (id: number): Promise> { - const url = environment.api + '/api/devices/daily-history/' + id; - const ref = this.http.get(url).toPromise(); - try { - const response: IResponse = await ref; - return response; - } catch (error) { - if (error.name === 'HttpErrorResponse') { - return GetNetworkError(); - } - return error; - } - } - public async GetRoles (): Promise> { - const url = environment.api + '/api/roles'; - const ref = this.http.get(url).toPromise(); - try { - const response: IResponse = await ref; - const collections = response.data.items; - for (const item of collections) { - this.store.dispatch({ - type: 'UPDATE_ROLE', - payload: item - }); - } - return response; - } catch (error) { - if (error.name === 'HttpErrorResponse') { - return GetNetworkError(); - } - return error; - } - } public async GetContactDetails (): Promise> { const url = environment.api + '/api/contact-details'; const ref = this.http.get(url).toPromise(); @@ -160,52 +34,6 @@ export class RequestsService { return error; } } - public async PostRole (role: IRole): Promise> { - const ref = this.http.post(environment.api + '/api/role' , role).toPromise(); - try { - const response: IResponse = await ref; - if (response && response.data && response.data.items && response.data.items[0]) { - const $role = response.data.items[0]; - if ($role) { - this.store.dispatch({ - type: 'UPDATE_ROLE', - payload: $role - }); - } - } - return response; - } catch (error) { - if (error.name === 'HttpErrorResponse') { - return GetNetworkError(); - } - return error; - } - } - public async PostDevice (device: CloudDevice): Promise> { - const ref = this.http.post(environment.api + '/api/device' , device).toPromise(); - try { - const response: IResponse = await ref; - if (response && response.data && response.data.items && response.data.items[0]) { - const $device = response.data.items[0]; - if ($device) { - this.store.dispatch({ - type: 'UPDATE_DEVICE', - payload: $device - }); - this.store.dispatch({ - type: 'CLEAR_UNCONNECTED_SOURCE', - payload: $device.datasource - }); - } - } - return response; - } catch (error) { - if (error.name === 'HttpErrorResponse') { - return GetNetworkError(); - } - return error; - } - } public async UpdateUserProfile (user: IUser): Promise> { const ref = this.http.post(environment.api + '/api/user/settings' , user).toPromise(); @@ -231,8 +59,6 @@ export class RequestsService { return error; } } - // public resetPassword(req: HttpRequest): IResponse { - public async RequestPasswordReset (username: string): Promise> { const ref = this.http.post(environment.api + '/api/forget-password' , {username}).toPromise(); @@ -246,100 +72,4 @@ export class RequestsService { return error; } } - - public async PostLocation (location: ILocation): Promise> { - const ref = this.http.post(environment.api + '/api/location' , location).toPromise(); - try { - const response: IResponse = await ref; - if (IsSuccessEntity(response)) { - const $location = response.data.items[0]; - if (! $location.id) { - $location.id = random(1000, 999999); - } - if ($location) { - this.store.dispatch({ - type: 'UPDATE_LOCATION', - payload: $location - }); - } - } - return response; - } catch (error) { - if (error.name === 'HttpErrorResponse') { - return GetNetworkError(); - } - return error; - } - } - async deleteLocation (id: number ) { - const ref = this.http.delete(environment.api + '/api/location/' + id).toPromise(); - try { - const response: IResponse = await ref; - if (IsSuccessEntity(response)) { - const $location = response.data.items[0]; - if (! $location.id) { - $location.id = random(1000, 999999); - } - if ($location) { - this.store.dispatch({ - type: 'DELETE_LOCATION', - payload: id - }); - } - } - return response; - } catch (error) { - if (error.name === 'HttpErrorResponse') { - return GetNetworkError(); - } - return error; - } - } - async deleteRole (id: number ) { - const ref = this.http.delete(environment.api + '/api/role/' + id).toPromise(); - try { - const response: IResponse = await ref; - if (IsSuccessEntity(response)) { - const $role = response.data.items[0]; - if ($role) { - this.store.dispatch({ - type: 'DELETE_ROLE', - payload: id - }); - } - } - return response; - } catch (error) { - if (error.name === 'HttpErrorResponse') { - return GetNetworkError(); - } - return error; - } - } - - async deleteDevice (id: number ) { - const ref = this.http.delete(environment.api + '/api/device/' + id).toPromise(); - try { - const response: IResponse = await ref; - if (IsSuccessEntity(response)) { - const $location = response.data.items[0]; - if (! $location.id) { - $location.id = random(1000, 999999); - } - if ($location) { - this.store.dispatch({ - type: 'DELETE_DEVICE', - payload: id - }); - } - } - return response; - } catch (error) { - if (error.name === 'HttpErrorResponse') { - return GetNetworkError(); - } - return error; - } - - } } diff --git a/src/app/components/progress-line/progress-line.component.html b/src/app/uikit/progress-line/progress-line.component.html similarity index 100% rename from src/app/components/progress-line/progress-line.component.html rename to src/app/uikit/progress-line/progress-line.component.html diff --git a/src/app/components/progress-line/progress-line.component.scss b/src/app/uikit/progress-line/progress-line.component.scss similarity index 100% rename from src/app/components/progress-line/progress-line.component.scss rename to src/app/uikit/progress-line/progress-line.component.scss diff --git a/src/app/components/progress-line/progress-line.component.ts b/src/app/uikit/progress-line/progress-line.component.ts similarity index 100% rename from src/app/components/progress-line/progress-line.component.ts rename to src/app/uikit/progress-line/progress-line.component.ts diff --git a/src/app/users/reducers/roles.reducer.ts b/src/app/users/reducers/roles.reducer.ts index 754a9020..f5049551 100644 --- a/src/app/users/reducers/roles.reducer.ts +++ b/src/app/users/reducers/roles.reducer.ts @@ -2,7 +2,6 @@ import { Action } from '@app/definitions'; import UpdateOrInsert from '@components/functions/UpdateOrInsert'; export function rolesReducer (state = [], action: Action) { - console.log('::', state, action); switch (action.type) { case 'RESET': return []; diff --git a/src/app/users/role-archive/role-archive.component.ts b/src/app/users/role-archive/role-archive.component.ts index 84cd91ea..c5903ca3 100644 --- a/src/app/users/role-archive/role-archive.component.ts +++ b/src/app/users/role-archive/role-archive.component.ts @@ -6,6 +6,8 @@ import { Store } from '@ngrx/store'; import { ActionsService } from '@app/services/actions.service'; import { UserModuleState } from '@app/users/user.module.defs'; import { UserRequestsService } from '@app/users/user-requests.service'; +import { TranslateService } from '@ngx-translate/core'; +import { NotificationService } from '@app/services/notification.service'; @Component({ selector: 'app-role-archive', @@ -13,8 +15,6 @@ import { UserRequestsService } from '@app/users/user-requests.service'; styleUrls: ['./role-archive.component.scss'] }) export class RoleArchiveComponent implements OnInit { - - public DeleteRole = this.actions.DeleteRole.bind(this.actions); public perms: Array = []; public roles: Array = []; constructor ( @@ -22,9 +22,19 @@ export class RoleArchiveComponent implements OnInit { private permissions: PermissionsService, private requests: UserRequestsService, private store: Store, + private translate: TranslateService, + private notification: NotificationService, private actions: ActionsService, ) { } + public DeleteRole (role: IRole) { + if (confirm( this.translate.get('Are you sure to delete this role?')['value'])) { + this.requests.deleteRole(role.id); + this.notification.InvokeRoleDelete(role); + this.router.navigateByUrl('/roles'); + } + } + async ngOnInit() { this.store.select('userModule').subscribe(({roles}) => { this.roles = (roles as Array); diff --git a/src/app/users/role-single/role-single.component.ts b/src/app/users/role-single/role-single.component.ts index ece1a221..fa252472 100644 --- a/src/app/users/role-single/role-single.component.ts +++ b/src/app/users/role-single/role-single.component.ts @@ -1,7 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { Router, ActivatedRoute } from '@angular/router'; import { PermissionsService } from '@services/permissions.service'; -import { RequestsService } from '@services/requests.service'; import { IRole, IPermission } from '@app/definitions'; import { Store } from '@ngrx/store'; import { error } from '@app/common'; @@ -9,6 +8,8 @@ import { IResponse } from 'response-type'; import { NotificationService } from '@app/services/notification.service'; import { ActionsService } from '@app/services/actions.service'; import { UserModuleState } from '@app/users/user.module.defs'; +import { UserRequestsService } from '@app/users/user-requests.service'; +import { TranslateService } from '@ngx-translate/core'; @Component({ selector: 'app-role-single', @@ -25,19 +26,28 @@ export class RoleSingleComponent implements OnInit { permissions: [], title: '' }; - public DeleteRole = this.actions.DeleteRole.bind(this.actions); public perms: Array = []; public roles: Array = []; constructor ( private router: Router, private permissions: PermissionsService, - private requests: RequestsService, + private requests: UserRequestsService, private store: Store, private route: ActivatedRoute, private notification: NotificationService, private actions: ActionsService, + private translate: TranslateService, + ) { } + public DeleteRole (role: IRole) { + if (confirm( this.translate.get('Are you sure to delete this role?')['value'])) { + this.requests.deleteRole(role.id); + this.notification.InvokeRoleDelete(role); + this.router.navigateByUrl('/roles'); + } + } + async ngOnInit() { this.store.select('userModule').subscribe(({roles}) => { this.roles = (roles as Array);