Skip to content

Commit

Permalink
Refactor module exports and improve type safety in components
Browse files Browse the repository at this point in the history
  • Loading branch information
pbachman committed Jan 13, 2025
1 parent 04d275d commit 9f1b876
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 160 deletions.
5 changes: 3 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { TranslateModule } from '@ngx-translate/core';
import { HttpClient } from '@angular/common/http';
import { TranslateLoader } from '@ngx-translate/core';
import { FormsModule } from '@angular/forms';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { MainModule } from './modules/main/main.module';
import { CoreModule } from './core/core.module';
import { TilesModule } from './modules/tiles/tiles.module';
Expand Down
3 changes: 0 additions & 3 deletions src/app/core/core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ import { Events } from './services/events.service';
IonicModule,
TranslateModule.forRoot(),
],
exports: [
MenuComponent
],
declarations: [
MenuComponent
],
Expand Down
90 changes: 46 additions & 44 deletions src/app/core/menu/menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { Component, OnInit } from '@angular/core';
import { LanguageService } from '../services/language.service';
import { AlertController, MenuController } from '@ionic/angular';
import { UserService } from '../services/user.service';
import { HttpErrorResponse } from '@angular/common/http';
import { Router } from '@angular/router';
import { DashboardService } from '../services/dashboard.service';
import { User } from '../models/user.model';
import { Events } from '../services/events.service';
import { HttpErrorResponse } from '@angular/common/http';

@Component({
selector: 'dasho-menu',
templateUrl: './menu.component.html',
styleUrls: ['./menu.component.scss'],
})
export class MenuComponent implements OnInit {
currentUser: User;
currentUser?: User;
settings: any;

constructor(
Expand All @@ -28,11 +28,11 @@ export class MenuComponent implements OnInit {
) {
this.pubSub.subscribe({
messageType: 'user:login',
callback: (response) => (this.currentUser = response.message.payload),
callback: (response: any) => (this.currentUser = response.message.payload),
});
}

ngOnInit() {}
ngOnInit() { }

/**
* Shows the dialog to change the password
Expand Down Expand Up @@ -68,18 +68,17 @@ export class MenuComponent implements OnInit {
},
{
text: i18n.changePassword.change,
handler: (data) => {
handler: (data: any) => {
if (
!data.passwordOld ||
!data.password ||
data.password !== data.passwordConfirm
) {
return false;
}

this.dashboardService
} else {
this.dashboardService
.changePassword(
this.currentUser.username,
this.currentUser?.username as string,
data.passwordOld,
data.password,
data.passwordConfirm,
Expand Down Expand Up @@ -109,6 +108,8 @@ export class MenuComponent implements OnInit {
return false;
},
);
return true;
}
},
},
],
Expand Down Expand Up @@ -140,7 +141,7 @@ export class MenuComponent implements OnInit {
},
{
text: i18n.invite.send,
handler: async (data) => {
handler: async (data: any) => {
if (this.userService.isMailInvalid(data.email)) {
const alert = await this.alertCtrl.create({
header: i18n.forgetPassword.alertInvalidTitle,
Expand All @@ -150,39 +151,40 @@ export class MenuComponent implements OnInit {
});
await alert.present();
return false;
} else {
this.dashboardService
.inviteFriends(this.currentUser?.username as string, data.email)
.subscribe(
async () => {
const alert = await this.alertCtrl.create({
header: i18n.invite.alertTitle,
subHeader: i18n.invite.alertSubTitle.replace(
'%email%',
data.email,
),
translucent: true,
backdropDismiss: false,
buttons: ['OK'],
});
await alert.present();
return true;
},
async (error: HttpErrorResponse) => {
const alert = await this.alertCtrl.create({
header: 'Error!',
message:
error.status === 0
? 'No Connection to the Backend!'
: error.error,
backdropDismiss: false,
buttons: ['OK'],
});
await alert.present();
return false;
},
);
return true;
}

this.dashboardService
.inviteFriends(this.currentUser.username, data.email)
.subscribe(
async () => {
const alert = await this.alertCtrl.create({
header: i18n.invite.alertTitle,
subHeader: i18n.invite.alertSubTitle.replace(
'%email%',
data.email,
),
translucent: true,
backdropDismiss: false,
buttons: ['OK'],
});
await alert.present();
return true;
},
async (error: HttpErrorResponse) => {
const alert = await this.alertCtrl.create({
header: 'Error!',
message:
error.status === 0
? 'No Connection to the Backend!'
: error.error,
backdropDismiss: false,
buttons: ['OK'],
});
await alert.present();
return false;
},
);
},
},
],
Expand All @@ -195,7 +197,7 @@ export class MenuComponent implements OnInit {
*/
configureTileSettings(): void {
this.dashboardService
.getSettings(this.currentUser.username)
.getSettings(this.currentUser?.username as string)
.subscribe((settings: any) => {
this.settings = settings;
this.menuCtrl.close();
Expand Down Expand Up @@ -227,7 +229,7 @@ export class MenuComponent implements OnInit {
const data = {
key: this.languageService.currentLanguage,
};
this.pubSub.publish('user:language', data );
this.pubSub.publish('user:language', data);
}

/**
Expand Down
22 changes: 11 additions & 11 deletions src/app/modules/admin/setting/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import { Events } from 'src/app/core/services/events.service';
standalone: false,
})
export class SettingPage implements OnInit {
currentUser: string;
error: string;
tiles: Array<Tile>;
settings: Array<Setting>;
selectedTile: string;
hasChanged: boolean;
currentUser?: string;
error?: string;
tiles: Array<Tile> = [];
settings: Array<Setting> = [];
selectedTile?: string;
hasChanged: boolean = false;

constructor(
private dashboardService: DashboardService,
Expand All @@ -43,12 +43,12 @@ export class SettingPage implements OnInit {

loadSettings(): void {
// get all Settings for the current User
this.dashboardService.getSettings(this.currentUser).subscribe(
this.dashboardService.getSettings(this.currentUser as string).subscribe(
(settings: Array<Setting>) => {
this.settings = settings;

// get all unassigned tiles.
this.settingService.getUnassignedTiles(this.currentUser).subscribe(
this.settingService.getUnassignedTiles(this.currentUser as string).subscribe(
(tiles: Array<Tile>) => {
this.tiles = tiles;
},
Expand All @@ -61,7 +61,7 @@ export class SettingPage implements OnInit {

addItem(): void {
this.settingService
.addConfigs(this.currentUser, this.selectedTile)
.addConfigs(this.currentUser as string, this.selectedTile as string)
.subscribe(
async () => {
const alert = await this.alertCtrl.create({
Expand All @@ -86,7 +86,7 @@ export class SettingPage implements OnInit {

saveItem(setting: Setting): void {
this.hasChanged = true;
this.dashboardService.saveSetting(this.currentUser, setting).subscribe(
this.dashboardService.saveSetting(this.currentUser as string, setting).subscribe(
async (saved: boolean) => {
if (saved) {
const alert = await this.alertCtrl.create({
Expand Down Expand Up @@ -124,7 +124,7 @@ export class SettingPage implements OnInit {
text: 'Yes',
handler: () => {
this.dashboardService
.deleteSetting(this.currentUser, setting)
.deleteSetting(this.currentUser as string, setting)
.subscribe(
(deleted: boolean) => {
if (deleted) {
Expand Down
14 changes: 7 additions & 7 deletions src/app/modules/admin/tile/tile.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { Component, OnInit } from '@angular/core';
import { HttpErrorResponse } from '@angular/common/http';
import { Setting } from '../../tiles/models/setting.model';
import { TileService } from './tile.service';
import { AlertController } from '@ionic/angular';
import { UserService } from 'src/app/core/services/user.service';
import { Tile } from '../models/tile.model';
import { Router } from '@angular/router';
import { Events } from 'src/app/core/services/events.service';
import { HttpErrorResponse } from '@angular/common/http';

@Component({
selector: 'tile-setting',
templateUrl: 'tile.html',
})
export class TilePage implements OnInit {
currentUser: string;
error: string;
tiles: Array<Tile>;
settings: Array<Setting>;
selectedTile: string;
hasChanged: boolean;
currentUser?: string;
error?: string;
tiles?: Array<Tile>;
settings: Array<Setting> = [];
selectedTile?: string;
hasChanged: boolean = false;

constructor(
private tileService: TileService,
Expand Down
Loading

0 comments on commit 9f1b876

Please sign in to comment.