Skip to content

Commit

Permalink
config changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nidhikachhawa24 committed Jun 17, 2024
2 parents 06d4f21 + 0442d80 commit 10a4dab
Show file tree
Hide file tree
Showing 37 changed files with 598 additions and 199 deletions.
71 changes: 57 additions & 14 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit, ViewChild, HostListener } from '@angular/core';
import { AppHeaderService } from './services/app-header.service';
import { HeaderConfig } from './appConstants';
import { IonRouterOutlet, ModalController, PopoverController } from '@ionic/angular';
import { IonRouterOutlet, ModalController, PopoverController, Platform } from '@ionic/angular';
import { TelemetryAutoSyncService } from './services/telemetry/telemetry.auto.sync.service';
import { App } from '@capacitor/app';
import { ScannerService } from './services/scan/scanner.service';
Expand All @@ -26,6 +26,8 @@ export class AppComponent implements OnInit {
count = 0;
optModalOpen = false;
languages: Array<any> = [];
private exitModalPresented = false;

@ViewChild('mainContent', { read: IonRouterOutlet, static: false }) routerOutlet!: IonRouterOutlet;
public environmentInjector = inject(EnvironmentInjector);

Expand All @@ -38,11 +40,15 @@ export class AppComponent implements OnInit {
public alertController: AlertController,
private location: Location,
private route: ActivatedRoute,
public platform: Platform,
private swUpdate: SwUpdate) {
this.initializeApp();
this.initialize();

}

initializeApp(): void {
history.pushState(null, '', location.href);
this.swUpdate.versionUpdates.subscribe(evt => {
switch (evt.type) {
case 'VERSION_DETECTED':
Expand All @@ -60,6 +66,56 @@ export class AppComponent implements OnInit {
});
}

async initialize() {
window.onpopstate = async () => {
history.pushState(null, '', location.href);
const modal = await this.modalCtrl.getTop();
if (modal) {
modal.dismiss();
}
// Add the popstate listener when the app initializes
/* if ((this.router.url === '/' || this.router.url === '/tabs/home') && !this.exitModalPresented && !modal) {
history.pushState(null, '', location.href);
await this.presentExitConfirmationModal();
// Push state to keep the URL the same after the user decides not to exit
} */
}
}

async presentExitConfirmationModal(){
this.exitModalPresented = true;
setTimeout(() => {
this.exitModalPresented = false;
}, 4000);
let modal: any;
this.optModalOpen = true;
modal = await this.modalCtrl.create({
component: AppExitComponent,
cssClass: 'sheet-modal',
breakpoints: [0.2],
showBackdrop: false,
backdropDismiss: false,
initialBreakpoint: 0.2,
handle: false,
handleBehavior: "none"
});
await modal.present();


modal.onDidDismiss().then((result: any) => {
this.optModalOpen = false;
if (result.data && result.data) {
window.close();

App.exitApp();

}
});
}

/* @HostListener('window:popstate', ['$event'])
async onPopState(event: any) {
Expand Down Expand Up @@ -146,30 +202,17 @@ export class AppComponent implements OnInit {
async ngOnInit() {
history.pushState(null, document.title, window.location.href);

// this.findSiteSubDomain();
this.headerService.headerConfigEmitted$.subscribe((config: HeaderConfig) => {
this.headerConfig = config;
});
this.headerService.filterConfigEmitted$.subscribe((val: any) => {
this.languages = val.languages;
console.log(val, this.languages);
})
this.autoSyncTelemetry()
App.addListener('pause', () => this.telemetryAutoSyncService.pause());
App.addListener('resume', () => this.telemetryAutoSyncService.continue());
}

// findSiteSubDomain(){
// const urlObj = new URL(document.baseURI);
// // Extract the hostname
// const hostname = urlObj.hostname; // e.g., "subdomain.example.com"
// // Split the hostname by dots
// const domainParts = hostname.split('.');
// localStorage.setItem('subDomain', domainParts[0])
// // Return the first part of the domain
// console.log("domain=====", domainParts[0]);
// }

async handleHeaderEvents($event: any) {
console.log('events', $event);
if (($event as any).name == 'scan') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
<div class="header-content" *ngIf="headerConfig?.actionButtons[0] !== 'bot'">
<ion-buttons slot="start" class="start-icon">
<ion-button [hidden]="headerConfig?.showbackButton">
<ion-icon aria-hidden="true" class="pitara-icon" src="{{configVariables.tenantLogo}}"></ion-icon>
<ion-icon aria-hidden="true" class="pitara-icon" src="{{configVariables?.tenantLogo}}"></ion-icon>
</ion-button>
<!-- Back button image -->
<ion-button [hidden]="!headerConfig?.showbackButton" (click)="emitEvent($event, 'back')">
<ion-icon class="back-btn" aria-hidden="true" src="assets/icon/back.svg"></ion-icon>
</ion-button>
</ion-buttons>
<ion-title role="heading" [ngClass]="{'title_bb': headerConfig?.showbackButton, 'animate_title': headerConfig?.pageTitle == appName}" aria-level="1"
*ngIf="!(headerConfig?.showbackButton && (headerConfig?.actionButtons?.indexOf('search') >=0 || headerConfig?.actionButtons?.indexOf('edit') >=0))">{{ configVariables.siteName }}</ion-title>
<ion-title role="heading" aria-level="1" *ngIf="headerConfig?.actionButtons?.indexOf('edit') >=0">{{ headerConfig.pageTitle }}</ion-title>
*ngIf="!(headerConfig?.showbackButton && (headerConfig?.actionButtons?.indexOf('search') >=0 || headerConfig?.actionButtons?.indexOf('edit') >=0))">{{ configVariables?.siteName }}</ion-title>
<ion-title role="heading" aria-level="1" *ngIf="headerConfig?.actionButtons?.indexOf('edit') >=0">{{ headerConfig?.pageTitle }}</ion-title>
<ion-input type="search" *ngIf="headerConfig?.showbackButton && headerConfig?.actionButtons?.indexOf('search') >=0" #searchInput [placeholder]="'SEARCH_HINT' | translate"></ion-input>
<ion-buttons slot="end" [hidden]="headerConfig?.showbackButton">
<ion-button (click)="emitEvent($event, 'search')">
Expand All @@ -36,13 +36,13 @@
</div>
<!--bot panel header-->
<div class="bot-back-panel" *ngIf="headerConfig?.actionButtons[0] === 'bot'">
<div class="bot-back-panel-container" [ngClass]="headerConfig.pageTitle === 'Parent Tara' || headerConfig.pageTitle === 'Teacher Tara' ? 'question-bot' : '' " (click)="emitEvent($event, 'back')"> <!--use the class "parent-bot" for parent bot panel-->
<div class="bot-back-panel-container" [ngClass]="headerConfig?.pageTitle === 'Parent Tara' || headerConfig?.pageTitle === 'Teacher Tara' ? 'question-bot' : '' " (click)="emitEvent($event, 'back')"> <!--use the class "parent-bot" for parent bot panel-->
<ion-icon aria-hidden="true" src="assets/icon/bot-back-icon.svg"></ion-icon>
<div class="bot-back-panel__title">{{headerConfig.pageTitle | translate}}</div>
<div class="bot-back-panel__title">{{headerConfig?.pageTitle | translate}}</div>
<div class="logo">
<img *ngIf="headerConfig.pageTitle === 'Katha Sakhi'" src="../../../assets/images/story_sakhi.png" alt=""/>
<img *ngIf="headerConfig.pageTitle === 'Parent Tara'" src="../../../assets/images/parent_sakhi.png" alt=""/>
<img *ngIf="headerConfig.pageTitle === 'Teacher Tara'" src="../../../assets/images/teacher_sakhi.png" alt=""/>
<img *ngIf="headerConfig?.pageTitle === 'Katha Sakhi'" src="../../../assets/images/story_sakhi.png" alt=""/>
<img *ngIf="headerConfig?.pageTitle === 'Parent Tara'" src="../../../assets/images/parent_sakhi.png" alt=""/>
<img *ngIf="headerConfig?.pageTitle === 'Teacher Tara'" src="../../../assets/images/teacher_sakhi.png" alt=""/>
</div>
</div>
</div>
Expand Down Expand Up @@ -75,7 +75,7 @@
<ion-footer>
<div class="footer_menu">
<ion-label class="sb-menu-item" role="button" menuClose>{{"Version: " | translate}} {{appVersion}}</ion-label>
<ion-label role="button" menuClose><span>{{ configVariables.siteName }}</span></ion-label>
<ion-label role="button" menuClose><span>{{ configVariables?.siteName }}</span></ion-label>
</div>
</ion-footer>
</ion-menu>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class ApplicationHeaderComponent implements OnInit {
defaultFilter!: any;
appVersion: string = ''
appName: string = ""
configVariables = ConfigVariables;
configVariables : any;

constructor(private utilService: UtilService,
private telemetryGeneratorService: TelemetryGeneratorService,
Expand All @@ -33,6 +33,14 @@ export class ApplicationHeaderComponent implements OnInit {
this.appVersion = `v${val.version}.${val.build}`
this.appName = val.name
})

ConfigVariables.then(config => {
console.log('Configuration:', config);
this.configVariables = config;
// Use the config data as needed
}).catch(error => {
console.error('Failed to load configuration:', error);
});
}

async ngOnInit() {
Expand Down
136 changes: 26 additions & 110 deletions src/app/config.ts
Original file line number Diff line number Diff line change
@@ -1,110 +1,26 @@
export const ConfigVariables = {
"tenantLogo": "assets/school/THSM_128x128.svg",
"siteName": "Hummingbird School in Assam",
"siteByLine": "Listen, Learn & Grow !!!",
"splashImage": "assets/school/THSM_152x152.png",
"headerFilters": [{
"defaultFilter": {
"id": "All",
"label": "All",
"query": "",
"filters": "All"
},
"additionalFilters": [
{
"id": "Stories",
"label": "Stories",
"query": "Stories",
"filters": "Stories"
},
{
"id": "Activities",
"label": "Activities",
"query": "Activities",
"filters": "Activities"
},
{
"id": "Songs",
"label": "Songs",
"query": "Songs",
"filters": "Songs"
},
{
"id": "Audio Books",
"label": "Audio Books",
"query": "Audio Books",
"filters": "Audio Books"
},
{
"id": "Handbooks",
"label": "Handbooks",
"query": "Handbooks",
"filters": "Handbooks"
},
]
}],
"languages": [
{
"id": "en",
"label": "English",
"default": false
},
{
"id": "hi",
"label": "हिंदी",
"default": true
},
{
"id": "as",
"label": "অসমীয়া",
"default": false
},
{
"id": "bn",
"label": "বাংলা",
"default": true
}
],
"kathaSakhiBotName": "Story Baideo",
"parentTaraBotName": "Parent Bondhu",
"teacherTaraBotName": "Teacher Bondhu",
// "apiEndPoint": "/dsep/search",
// "bookmark": "BookMark",
// "rating": "Rating",
// "share": "Share",
// "pagination": "10",
// "orderBy": "",
// "filterBy": "default",
"footerText": "Developed with ❤️ by Tekdi Technologies ",
"headerColor": "brown",
"headerFontSize": "16",
"footerColor": "brown",
"footerFontSize": "16",
// "positionByLine": "false",
// "positionLogo": "false",
// "positionSiteName": "false",
// "labelTitle": "शीर्षक",
// "labelAuthor": "लेखक",
// "labelDesc": "Desc",
// "labelRating": "Rating",
// "displayOrder": {
// "title": "3",
// "author": "1",
// "description": "2",
// "publisher": "4"
// },
// "filters": {
// "minAge": "",
// "language": "",
// "contentType": ""
// },
// "searchFilters":{
// "age":["1","2","3","4","5","6","7","8","9","10"],
// "language":["English","Hindi","Gujarati","Tamil","Kannada"],
// "type":["Video","Audio","Read","Others"]
// },
// "contentSource":{
// "source":["onest","SB"]
// },
// "logo": "photo-1492144534655-ae79c964c9d71699539070789.avif"
}
// config.ts
const urlObj = new URL(document.baseURI);
const hostname = urlObj.hostname; // e.g., "subdomain.example.com"
const domainParts = hostname.split('.');
console.log(domainParts);
const jsonFilename = domainParts[0] + '.json';
const jsonUrl = `../assets/appConfig/${jsonFilename}`;
// const jsonUrl = `../assets/appConfig/localhost.json`;

console.log(`Fetching configuration from: ${jsonUrl}`);

export const ConfigVariables = fetch(jsonUrl)
.then(response => {
console.log({ response });
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
console.log('Fetched data:', data);
return data; // Return the fetched data so that it can be used by other parts of the application
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
});
20 changes: 15 additions & 5 deletions src/app/pages/home/home.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class HomePage implements OnInit, OnTabViewWillEnter, OnDestroy {
networkChangeSub: Subscription | null = null;
selectedLang: any = "";
appName: string = "";
configVariables = ConfigVariables;
configVariables : any;
responseList: Array<any> = [];
constructor(
private headerService: AppHeaderService,
Expand All @@ -70,6 +70,15 @@ export class HomePage implements OnInit, OnTabViewWillEnter, OnDestroy {
private lcoalNotifService: LocalNotificationService,
private appUpdateService: AppUpdateService,
private confirmService: ConfirmService) {

ConfigVariables.then(config => {
console.log('Configuration:', config);
this.configVariables = config;
// Use the config data as needed
}).catch(error => {
console.error('Failed to load configuration:', error);
});

App.getInfo().then(info => {this.appName = info.name});
this.configContents = [];
this.contentList = [];
Expand Down Expand Up @@ -103,19 +112,20 @@ export class HomePage implements OnInit, OnTabViewWillEnter, OnDestroy {
// }

async ngOnDestroy() {
const modal = await this.modalCtrl.getTop();
if (modal) {
modal.dismiss();
}
try {
this.langChangeSubscription && this.langChangeSubscription.unsubscribe()
this.networkChangeSub && this.networkChangeSub.unsubscribe();
} catch (error) {
console.log(`error in unsubscribe`, error)
}
const modal = await this.modalCtrl.getTop();
if (modal) {
modal.dismiss();
}
}

async ngOnInit(): Promise<void> {

this.headerService.headerEventEmitted$.subscribe(async (val) => {
if(val == 'language') {
let lang = await this.storage.getData('lang');
Expand Down
6 changes: 3 additions & 3 deletions src/app/pages/search/search.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ export class SearchPage implements OnInit, OnTabViewWillEnter {
if(audio) {
this.showSheenAnimation = true;
let res = await this.makeSearchContextApiCall(data, audio);
if (res?.input) {
if(res.input?.sourceText) {
this.searchKeywords = res.input.sourceText;
if (res?.audioText) {
if(res.audioText) {
this.searchKeywords = res.audioText;
}
this.handleContentSearch(res, audio);
} else {
Expand Down
Loading

0 comments on commit 10a4dab

Please sign in to comment.