Skip to content

Commit

Permalink
Solara
Browse files Browse the repository at this point in the history
  • Loading branch information
IdeaS0ft committed Sep 8, 2024
1 parent 91926f9 commit 65aa815
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 105 deletions.
8 changes: 8 additions & 0 deletions solara/lib/core/brands/brands_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ def brand_name(brand_key)
brand_data(brand_key)["name"]
end

def brand_with_configurations(brand_key)
configurations = BrandConfigurationsManager.new(brand_key).create
{
brand: brand_data(brand_key),
configurations: configurations
}
end

def brand_data(brand_key)
brands_list.find { |brand| brand["key"] == brand_key }
end
Expand Down
6 changes: 2 additions & 4 deletions solara/lib/core/dashboard/brand/BrandController.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BrandController {
async initLoal() {
try {
const result = await this.model.fetchBrandDetails();
await this.onLoadSections(result);
await this.onLoadSections(result.result);
const {isCurrentBrand, contentChanged} = await this.model.fetchCurrentBrand();

if (!isCurrentBrand) {
Expand Down Expand Up @@ -204,11 +204,9 @@ class BrandController {
const sectionElements = Array.from(sectionsContainer.querySelectorAll('.section'));

const configurations = sectionElements.map(sectionElement => {
const subtitle = sectionElement.dataset.subtitle;
return {
key: sectionElement.dataset.key,
name: sectionElement.dataset.name,
subtitle: subtitle === null || subtitle === 'undefined' ? '' : subtitle,
inputType: sectionElement.dataset.inputType,
content: this.getSectionConfiguration(sectionElement)
};
Expand All @@ -227,7 +225,7 @@ class BrandController {
// Create a link element to download the Blob
const a = document.createElement('a');
a.href = url;
a.download = `${brandKey}-configurations.json`; // Set the filename
a.download = `${brandKey}-solara-configurations.json`; // Set the filename
document.body.appendChild(a);
a.click(); // Programmatically click the link to trigger the download
document.body.removeChild(a); // Clean up the DOM
Expand Down
2 changes: 1 addition & 1 deletion solara/lib/core/dashboard/brand/BrandModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class BrandModel {

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

Expand Down
22 changes: 6 additions & 16 deletions solara/lib/core/dashboard/brand/BrandView.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ class BrandView {

async initLoal() {
this.allBrandsButton.style.display = 'block'
this.downloadBrandBtn.display = 'none'
this.downloadBrandBtn.style.display = 'none'
this.toggleAddBrandContainer(false);
}

async initRemote() {
this.allBrandsButton.style.display = 'none'
this.downloadBrandBtn.display = 'block'
this.downloadBrandBtn.style.display = 'block'
this.toggleAddBrandContainer(true);

this.addNewBrandBtn.addEventListener('click', async () => {
Expand Down Expand Up @@ -71,7 +71,6 @@ class BrandView {
{
"key": "theme",
"name": "Theme Configuration",
"subtitle": "theme.json",
"inputType": "color",
"content": {
"name": "BrandTheme",
Expand Down Expand Up @@ -123,14 +122,12 @@ class BrandView {
{
"key": "brand_config",
"name": "Brand Configuration",
"subtitle": "brand_config.json",
"inputType": "text",
"content": {}
},
{
"key": "android_config",
"name": "Android Platform Configuration",
"subtitle": "android_config.json",
"inputType": "text",
"content": {
"brandName": "",
Expand All @@ -143,7 +140,6 @@ class BrandView {
{
"key": "android_signing",
"name": "Android Signing",
"subtitle": "android_signing.json",
"inputType": "text",
"content": {
"storeFile": "",
Expand All @@ -155,7 +151,6 @@ class BrandView {
{
"key": "ios_config",
"name": "iOS Platform Configuration",
"subtitle": "ios_config.json",
"inputType": "text",
"content": {
"PRODUCT_NAME": "",
Expand All @@ -168,7 +163,6 @@ class BrandView {
{
"key": "ios_signing",
"name": "iOS Signing",
"subtitle": "ios_signing.json",
"inputType": "text",
"content": {
"CODE_SIGN_IDENTITY": "",
Expand Down Expand Up @@ -249,7 +243,6 @@ class BrandView {
configList.push({
key: file.key,
name: file.name,
subtitle: `${file.key}.json`,
inputType: file.input_type,
content: JSON.parse(fileContent)
});
Expand Down Expand Up @@ -291,7 +284,6 @@ class BrandView {

section.dataset.key = sectionInfo.key
section.dataset.name = sectionInfo.name
section.dataset.subtitle = sectionInfo.subtitle
section.dataset.inputType = sectionInfo.inputType

const titleContainer = document.createElement('div');
Expand All @@ -301,12 +293,10 @@ class BrandView {
title.textContent = sectionInfo.name;
titleContainer.appendChild(title);

if (sectionInfo.subtitle) {
const subtitleElement = document.createElement('p');
subtitleElement.className = 'section-subtitle';
subtitleElement.textContent = sectionInfo.subtitle;
titleContainer.appendChild(subtitleElement);
}
const subtitleElement = document.createElement('p');
subtitleElement.className = 'section-subtitle';
subtitleElement.textContent = `${sectionInfo.key}.json`;
titleContainer.appendChild(subtitleElement);

section.appendChild(titleContainer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ def mount
query = CGI.parse(req.query_string)
brand_key = query['brand_key']&.first

configurations = BrandConfigurationsManager.new(brand_key).create
response_data = {
brand: BrandsManager.instance.brand(brand_key),
configurations: configurations
}
response_data = BrandsManager.instance.brand_with_configurations(brand_key)
res.body = JSON.generate({ success: true, message: "Configurations response", result: response_data })
res['Content-Type'] = 'application/json'
rescue StandardError => e
Expand All @@ -20,77 +16,3 @@ def mount

end

class BrandConfigurationsManager

def initialize(brand_key)
@brand_key = brand_key
end

def template_with_key(key)
templates.select { |section| section[:key] === key }.first
end

def templates
[
{
key: 'theme',
name: 'Theme Configuration',
input_type: 'color',
path: FilePath.brand_theme(@brand_key)
},
{
key: 'brand_config',
name: 'Brand Configuration',
input_type: 'text',
path: FilePath.brand_config(@brand_key)
},
{
key: 'android_config',
name: 'Android Platform Configuration',
input_type: 'text',
path: FilePath.android_brand_config(@brand_key)
},
{
key: 'android_signing',
name: 'Android Signing',
input_type: 'text',
path: FilePath.brand_signing(@brand_key, Platform::Android)
},
{
key: 'ios_config',
name: 'iOS Platform Configuration',
input_type: 'text',
path: FilePath.ios_config(@brand_key)
},
{
key: 'ios_signing',
name: 'iOS Signing',
input_type: 'text',
path: FilePath.brand_signing(@brand_key, Platform::IOS)
}
]
end

def create
config_templates = templates

config_templates.map do |template|
create_config_item(
template[:key],
template[:name],
template[:input_type],
template[:path].tap { |p| File.expand_path(p) }
)
end
end

def create_config_item(key, name, input_type, path)
{
key: key,
name: name,
subtitle: FileManager.get_relative_path_to_root(path),
inputType: input_type,
content: JSON.parse(File.read(path)),
}
end
end
73 changes: 73 additions & 0 deletions solara/lib/core/dashboard/handler/brand_configurations_manager.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
class BrandConfigurationsManager

def initialize(brand_key)
@brand_key = brand_key
end

def template_with_key(key)
templates.select { |section| section[:key] === key }.first
end

def templates
[
{
key: 'theme',
name: 'Theme Configuration',
input_type: 'color',
path: FilePath.brand_theme(@brand_key)
},
{
key: 'brand_config',
name: 'Brand Configuration',
input_type: 'text',
path: FilePath.brand_config(@brand_key)
},
{
key: 'android_config',
name: 'Android Platform Configuration',
input_type: 'text',
path: FilePath.android_brand_config(@brand_key)
},
{
key: 'android_signing',
name: 'Android Signing',
input_type: 'text',
path: FilePath.brand_signing(@brand_key, Platform::Android)
},
{
key: 'ios_config',
name: 'iOS Platform Configuration',
input_type: 'text',
path: FilePath.ios_config(@brand_key)
},
{
key: 'ios_signing',
name: 'iOS Signing',
input_type: 'text',
path: FilePath.brand_signing(@brand_key, Platform::IOS)
}
]
end

def create
config_templates = templates

config_templates.map do |template|
create_config_item(
template[:key],
template[:name],
template[:input_type],
template[:path].tap { |p| File.expand_path(p) }
)
end
end

def create_config_item(key, name, input_type, path)
{
key: key,
name: name,
inputType: input_type,
content: JSON.parse(File.read(path)),
}
end
end
5 changes: 1 addition & 4 deletions solara/lib/core/doctor/schema/brand_configurations.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
"name": {
"type": "string"
},
"subtitle": {
"type": "string"
},
"inputType": {
"type": "string",
"enum": ["color", "text"]
Expand All @@ -37,7 +34,7 @@
"additionalProperties": {}
}
},
"required": ["key", "name", "subtitle", "inputType", "content"]
"required": ["key", "name", "inputType", "content"]
}
}
},
Expand Down
25 changes: 25 additions & 0 deletions solara/lib/core/scripts/brand_exporter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'json'
require 'fileutils'

class BrandExporter

def start(brand_key, path)
if !path.nil? && !path.strip.empty? && !File.directory?(path)
Solara.logger.failure("#{path} is not a directory. Please specify a valid directory.")
return
end

directory = path || FilePath.project_root

brand = BrandsManager.instance.brand_with_configurations(brand_key)
json = JSON.pretty_generate(brand)
json_file_path = File.join(directory, "#{brand_key}-solara-configurations.json")

# Create the file if it does not exist
File.open(json_file_path, 'w') do |file|
file.write(json)
end

Solara.logger.success("Successfully exportd brand #{brand_key} to: #{json_file_path}")
end
end
17 changes: 16 additions & 1 deletion solara/lib/solara.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def status
SolaraManager.new.status
end

desc "import -configurations --brand_key YOUR_BRAND_KEY", "Import a brand's configurations. If the brand is existing, it will be updated with these configurations, otherwise, a new brand will be onboarded."
desc "import -configurations CONFIGURATIONS_JSON_FILE --brand_key YOUR_BRAND_KEY", "Import the brand's configurations. If the brand is existing, it will be updated with these configurations, otherwise, a new brand will be onboarded."

method_option :configurations, :type => :string, :aliases => "-c"
method_option :brand_key, :type => :string, :aliases => "-k"
Expand All @@ -88,6 +88,21 @@ def import
SolaraManager.new.import(configurations)
end


desc "export --brand_key YOUR_BRAND_KEY --directory DIRECTORY", "Export the brand's configurations. The brand details will be saved to a JSON file at the specified location."

method_option :brand_key, :type => :string, :aliases => "-k"
method_option :directory, :type => :string, :aliases => "-d"
def export
check_project_health

brand_key = options['brand_key']
directory = options['directory']


SolaraManager.new.export(brand_key, directory)
end

desc "onboard -k YOUR_BRAND_KEY -n YOUR_BRAND_NAME", "Onboard a new brand"
method_option :brand_key, :type => :string, :aliases => "-k"
method_option :brand_name, :type => :string, :aliases => "-n"
Expand Down
Loading

0 comments on commit 65aa815

Please sign in to comment.