Skip to content

Commit

Permalink
Solara
Browse files Browse the repository at this point in the history
  • Loading branch information
ideyaa committed Sep 9, 2024
1 parent f198211 commit b172ab3
Show file tree
Hide file tree
Showing 4 changed files with 225 additions and 225 deletions.
29 changes: 28 additions & 1 deletion solara/lib/core/dashboard/brand/BrandController.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class BrandController {
this.deleteField = this.deleteField.bind(this);
this.initializeEventListeners();
this.view.setOnSectionChangedHandler(this.onSectionChanged.bind(this));
this.view.setOnAddBrand(this.onLoadSections.bind(this));
this.view.setOnDeleteFieldHandler(this.deleteField.bind(this));
}

Expand All @@ -24,6 +23,34 @@ class BrandController {
}

async initRemote() {
this.view.uploadBrandBtn.addEventListener('click', async () => {
try {
const dirHandle = await window.showDirectoryPicker();
const configurations = await this.model.createBrandConfigurationsFromDirectory(dirHandle);

this.view.showOnboardBrandForm((key, name) => {
this.addBrand(key, name, configurations)
})
} catch (error) {
console.error('Error:', error);
}
});
this.view.addNewBrandBtn.addEventListener('click', async () => {
this.view.showOnboardBrandForm(async (key, name) => {
const configurations = await this.model.createNewBrandConfogurations()
console.log(configurations)
await this.addBrand(key, name, configurations)
})
});
}

async addBrand(key, name, configurations) {
const result = {
brand: {key: key, name: name},
configurations: configurations
};
await this.onLoadSections(result)
this.view.toggleAddBrandContainer(false);
}

async initLoal() {
Expand Down
12 changes: 10 additions & 2 deletions solara/lib/core/dashboard/brand/BrandModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class BrandModel {

const sourceFromUrl = this.getQueryFromUrl('source');
// TODO: uncomment
this.source = sourceFromUrl === DataSource.LOCAL ? DataSource.LOCAL : DataSource.REMOTE;
// this.source = DataSource.REMOTE;
// this.source = sourceFromUrl === DataSource.LOCAL ? DataSource.LOCAL : DataSource.REMOTE;
this.source = DataSource.REMOTE;
}

getQueryFromUrl(name) {
Expand Down Expand Up @@ -77,6 +77,14 @@ class BrandModel {
throw new Error('Unknown data source');
}
}

async createNewBrandConfogurations() {
return await this.remoteSource.createNewBrandConfogurations();
}

async createBrandConfigurationsFromDirectory(dirHandle) {
return await this.remoteSource.createBrandConfigurationsFromDirectory(dirHandle);
}
}

export default BrandModel;
222 changes: 0 additions & 222 deletions solara/lib/core/dashboard/brand/BrandView.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,232 +47,14 @@ class BrandView {
this.downloadBrandBtn.style.display = 'block'
this.toggleAddBrandContainer(true);

this.addNewBrandBtn.addEventListener('click', async () => {
this.showOnboardBrandForm((key, name) => {
this.addNewBrand(key, name)
})
});

this.uploadBrandBtn.addEventListener('click', async () => {
try {
const dirHandle = await window.showDirectoryPicker();
const configurations = await this.getBrandConfigurationsFromFolder(dirHandle);

this.showOnboardBrandForm((key, name) => {
this.addBrand(key, name, configurations)
})
} catch (error) {
console.error('Error:', error);
}
});
}

async addNewBrand(key, name) {
const configurations_template = `
[
{
"key": "theme",
"name": "Theme Configuration",
"inputType": "color",
"content": {
"name": "BrandTheme",
"version": "1.0.0",
"colors": {
"primary": "#CAAC16",
"secondary": "#5AC8FA",
"background": "#FFFFFF",
"surface": "#F2F2F7",
"error": "#FF3B30",
"onPrimary": "#FFFFFF",
"onSecondary": "#000000",
"onBackground": "#000000",
"onSurface": "#000000",
"onError": "#FFFFFF"
},
"typography": {
"fontFamily": {
"regular": "Roboto",
"medium": "Roboto-Medium",
"bold": "Roboto-Bold"
},
"fontSize": {
"small": 12,
"medium": 16,
"large": 20,
"extraLarge": 24
}
},
"spacing": {
"small": 8,
"medium": 16,
"large": 24,
"extraLarge": 32
},
"borderRadius": {
"small": 4,
"medium": 8,
"large": 12
},
"elevation": {
"none": 0,
"low": 2,
"medium": 4,
"high": 8
}
}
},
{
"key": "brand_config",
"name": "Brand Configuration",
"inputType": "text",
"content": {}
},
{
"key": "android_config",
"name": "Android Platform Configuration",
"inputType": "text",
"content": {
"brandName": "",
"applicationId": "",
"versionName": "1.0.0",
"versionCode": 1,
"sourceSets": []
}
},
{
"key": "android_signing",
"name": "Android Signing",
"inputType": "text",
"content": {
"storeFile": "",
"keyAlias": "",
"storePassword": "",
"keyPassword": ""
}
},
{
"key": "ios_config",
"name": "iOS Platform Configuration",
"inputType": "text",
"content": {
"PRODUCT_NAME": "",
"PRODUCT_BUNDLE_IDENTIFIER": "",
"MARKETING_VERSION": "1.0.0",
"BUNDLE_VERSION": "1",
"APL_MRCH_ID": ""
}
},
{
"key": "ios_signing",
"name": "iOS Signing",
"inputType": "text",
"content": {
"CODE_SIGN_IDENTITY": "",
"DEVELOPMENT_TEAM": "",
"PROVISIONING_PROFILE_SPECIFIER": "",
"CODE_SIGN_STYLE": "Automatic",
"CODE_SIGN_ENTITLEMENTS": ""
}
}
]`;
const configurations = JSON.parse(configurations_template);
await this.addBrand(key, name, configurations)
}

async addBrand(key, name, configurations) {
// TODO: remove later
const json = JSON.stringify(configurations, null, 2);
console.log(json, this);

const result = {
configurations: configurations,
brand: {key: key, name: name}
};
this.onAddBrand(result)
this.toggleAddBrandContainer(false);
}

toggleAddBrandContainer(show) {
this.addBrandContainer.style.display = show ? 'block' : 'none';
this.brandDetailsContainer.style.display = show ? 'none' : 'block';
}

async getBrandConfigurationsFromFolder(dirHandle) {
const configList = [];
const expectedFiles = [
{
key: 'theme',
name: 'Theme Configuration',
input_type: 'color',
filename: 'theme.json'
},
{
key: 'brand_config',
name: 'Brand Configuration',
input_type: 'text',
filename: 'brand_config.json'
},
{
key: 'android_config',
name: 'Android Platform Configuration',
input_type: 'text',
filename: 'android_config.json'
},
{
key: 'android_signing',
name: 'Android Signing',
input_type: 'text',
filename: 'android_signing.json'
},
{
key: 'ios_config',
name: 'iOS Platform Configuration',
input_type: 'text',
filename: 'ios_config.json'
},
{
key: 'ios_signing',
name: 'iOS Signing',
input_type: 'text',
filename: 'ios_signing.json'
}
];

for (const file of expectedFiles) {
try {
const fileContent = await this.findAndReadFile(dirHandle, file.filename);
if (fileContent) {
configList.push({
key: file.key,
name: file.name,
inputType: file.input_type,
content: JSON.parse(fileContent)
});
}
} catch (error) {
console.warn(`File not found or invalid JSON: ${file.filename}`);
}
}

return configList;
}

async findAndReadFile(dirHandle, filename) {
const queue = [dirHandle];
while (queue.length > 0) {
const currentHandle = queue.shift();
for await (const entry of currentHandle.values()) {
if (entry.kind === 'file' && entry.name === filename) {
const file = await entry.getFile();
return await file.text();
} else if (entry.kind === 'directory') {
queue.push(entry);
}
}
}
return null;
}

updateAppNameTitle(brandName) {
const brandNametitle = document.getElementById('brandNametitle');
if (brandNametitle) {
Expand Down Expand Up @@ -449,10 +231,6 @@ class BrandView {
this.onSectionChanged = handler;
}

setOnAddBrand(handler) {
this.onAddBrand = handler;
}

setOnDeleteFieldHandler(handler) {
this.onDeleteField = handler;
}
Expand Down
Loading

0 comments on commit b172ab3

Please sign in to comment.