-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
204 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
solara/lib/core/dashboard/brand/source/BrandLocalSource.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
class BrandLocalSource { | ||
constructor() { | ||
this.savingInProgress = false; | ||
} | ||
|
||
getQueryFromUrl(name) { | ||
const urlParams = new URLSearchParams(window.location.search); | ||
return urlParams.get(name); | ||
} | ||
|
||
async fetchSections(brandKey) { | ||
try { | ||
if (!brandKey) { | ||
throw new Error('No brand_key provided in URL'); | ||
} | ||
|
||
const url = `/sections?brand_key=${encodeURIComponent(brandKey)}`; | ||
console.log('Fetching sections from:', url); | ||
|
||
const response = await fetch(url); | ||
const result = await response.json(); | ||
if (!response.ok) { | ||
throw new Error(result.error); | ||
} | ||
return {sectionItems: result.result.sections, brandName: result.result.brand_name}; | ||
} catch (error) { | ||
console.error('Error fetching config sections:', error); | ||
throw error; | ||
} | ||
} | ||
|
||
async fetchCurrentBrand(brandKey) { | ||
try { | ||
const response = await fetch('/brand/current'); | ||
let result = await response.json(); | ||
if (!response.ok) { | ||
throw new Error(result.error); | ||
} | ||
let isCurrentBrand = result.key === brandKey; | ||
return {isCurrentBrand: isCurrentBrand, contentChanged: result.content_changed}; | ||
} catch (error) { | ||
console.error('Error fetching current brand:', error); | ||
throw error; | ||
} | ||
} | ||
|
||
async saveSection(sectionItem, configuration, brandKey) { | ||
if (this.savingInProgress) return; | ||
this.savingInProgress = true; | ||
|
||
const dataToSend = { | ||
brand_key: brandKey, | ||
key: sectionItem.key, | ||
data: configuration | ||
}; | ||
|
||
try { | ||
const response = await fetch(`/section/edit`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify(dataToSend) | ||
}); | ||
|
||
const result = await response.json(); | ||
|
||
if (!response.ok) { | ||
throw new Error(result.error); | ||
} | ||
|
||
console.log(`${sectionItem.name} configuration saved successfully!`); | ||
return true; | ||
} catch (error) { | ||
console.error('Error saving configuration:', error); | ||
throw error; | ||
} finally { | ||
this.savingInProgress = false; | ||
} | ||
} | ||
|
||
async switchToBrand(brandKey) { | ||
try { | ||
const response = await fetch('/switch', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({brand_key: brandKey}), | ||
}); | ||
|
||
const result = await response.json(); | ||
|
||
if (!response.ok) { | ||
throw new Error(result.error); | ||
} | ||
|
||
console.log('Switch to brand result:', result); | ||
return true; | ||
} catch (error) { | ||
console.error('Error switching to brand:', error); | ||
throw error; | ||
} | ||
} | ||
|
||
async checkBrandHealth(brandKey) { | ||
try { | ||
const response = await fetch(`/brand/doctor?brand_key=${encodeURIComponent(brandKey)}`); | ||
const result = await response.json(); | ||
|
||
if (!response.ok) { | ||
throw new Error(result.error); | ||
} | ||
|
||
return result.result; | ||
} catch (error) { | ||
console.error('Error calling doctor API:', error); | ||
throw error; | ||
} | ||
} | ||
} | ||
|
||
export default BrandLocalSource; |
27 changes: 27 additions & 0 deletions
27
solara/lib/core/dashboard/brand/source/BrandRemoteSource.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class BrandRemoteSource { | ||
constructor() { | ||
} | ||
|
||
// Keep functions for future implementation | ||
async fetchSections(brandKey) { | ||
// Empty for now | ||
} | ||
|
||
async fetchCurrentBrand(brandKey) { | ||
// Empty for now | ||
} | ||
|
||
async saveSection(sectionItem, configuration, brandKey) { | ||
// Empty for now | ||
} | ||
|
||
async switchToBrand(brandKey) { | ||
// Empty for now | ||
} | ||
|
||
async checkBrandHealth(brandKey) { | ||
// Empty for now | ||
} | ||
} | ||
|
||
export default BrandRemoteSource; |