added defaults
This commit is contained in:
parent
f0700fda14
commit
67adb8ac4d
BIN
asm_app/public/hospital.png
Normal file
BIN
asm_app/public/hospital.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 46 KiB |
@ -1,3 +1,5 @@
|
|||||||
|
import { DEFAULT_FRAPPE_BASE_URL } from './defaults';
|
||||||
|
|
||||||
// API Configuration Types
|
// API Configuration Types
|
||||||
interface ApiConfig {
|
interface ApiConfig {
|
||||||
BASE_URL: string;
|
BASE_URL: string;
|
||||||
@ -7,8 +9,10 @@ interface ApiConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const API_CONFIG: ApiConfig = {
|
const API_CONFIG: ApiConfig = {
|
||||||
// Use same-origin relative URLs in production so the app works on any domain.
|
// Backend URL - Use proxy in development, direct URL in production
|
||||||
BASE_URL: import.meta.env.VITE_FRAPPE_BASE_URL || '',
|
BASE_URL: import.meta.env.DEV
|
||||||
|
? '' // Use relative URLs in development (goes through Vite proxy)
|
||||||
|
: import.meta.env.VITE_FRAPPE_BASE_URL || DEFAULT_FRAPPE_BASE_URL,
|
||||||
|
|
||||||
// API Endpoints
|
// API Endpoints
|
||||||
ENDPOINTS: {
|
ENDPOINTS: {
|
||||||
|
|||||||
13
asm_app/src/config/defaults.ts
Normal file
13
asm_app/src/config/defaults.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* Default Application Configurations & Fallbacks for Assir ASM UI App
|
||||||
|
* Centralized constants for hospital/tenant names, default warehouses, logos, and endpoints.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const DEFAULT_HOSPITAL = 'Assir Central Hospital';
|
||||||
|
export const DEFAULT_WAREHOUSE = 'Stores - AGH';
|
||||||
|
|
||||||
|
// Fallback Frappe Backend Base URL
|
||||||
|
export const DEFAULT_FRAPPE_BASE_URL = 'https://asir-ch.seeraarabia.com';
|
||||||
|
|
||||||
|
// Default logos
|
||||||
|
export const DEFAULT_HOSPITAL_LOGO = '/files/hospital.png';
|
||||||
@ -17,6 +17,7 @@ import CommentSection from '../components/CommentSection';
|
|||||||
import WoFeedbackSummary from '../components/WoFeedbackSummary';
|
import WoFeedbackSummary from '../components/WoFeedbackSummary';
|
||||||
import apiService from '../services/apiService';
|
import apiService from '../services/apiService';
|
||||||
import API_CONFIG from '../config/api';
|
import API_CONFIG from '../config/api';
|
||||||
|
import { DEFAULT_WAREHOUSE } from '../config/defaults';
|
||||||
import useDefaultHospital from '../hooks/useDefaultHospital';
|
import useDefaultHospital from '../hooks/useDefaultHospital';
|
||||||
import { isSiteEnabledHospital, buildMobileTeamSiteFilters } from '../utils/hospitalUtils';
|
import { isSiteEnabledHospital, buildMobileTeamSiteFilters } from '../utils/hospitalUtils';
|
||||||
import useUserPhccSiteFilter from '../hooks/useUserPhccSiteFilter';
|
import useUserPhccSiteFilter from '../hooks/useUserPhccSiteFilter';
|
||||||
@ -339,9 +340,6 @@ const WorkOrderDetail: React.FC = () => {
|
|||||||
docData: workOrderDocData, // Pass document data for condition evaluation
|
docData: workOrderDocData, // Pass document data for condition evaluation
|
||||||
});
|
});
|
||||||
|
|
||||||
// Default warehouse for new stock items
|
|
||||||
const DEFAULT_WAREHOUSE = 'Al Jouf Central Warehouse - AJH';
|
|
||||||
|
|
||||||
// Stock warnings state
|
// Stock warnings state
|
||||||
const [stockWarnings, setStockWarnings] = useState<Record<number, string>>({});
|
const [stockWarnings, setStockWarnings] = useState<Record<number, string>>({});
|
||||||
|
|
||||||
|
|||||||
@ -83,7 +83,8 @@ app_license = "mit"
|
|||||||
# ------------
|
# ------------
|
||||||
|
|
||||||
# before_install = "asm_ui_app.install.before_install"
|
# before_install = "asm_ui_app.install.before_install"
|
||||||
# after_install = "asm_ui_app.install.after_install"
|
after_install = "asm_ui_app.install.after_install"
|
||||||
|
after_migrate = "asm_ui_app.install.after_migrate"
|
||||||
|
|
||||||
# Uninstallation
|
# Uninstallation
|
||||||
# ------------
|
# ------------
|
||||||
|
|||||||
64
asm_ui_app/install.py
Normal file
64
asm_ui_app/install.py
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
import os
|
||||||
|
import frappe
|
||||||
|
|
||||||
|
|
||||||
|
def after_install():
|
||||||
|
"""Executed after the app is installed on a site."""
|
||||||
|
setup_default_files()
|
||||||
|
|
||||||
|
|
||||||
|
def after_migrate():
|
||||||
|
"""Executed after 'bench migrate' is run on a site."""
|
||||||
|
setup_default_files()
|
||||||
|
|
||||||
|
|
||||||
|
def setup_default_files():
|
||||||
|
"""Ensure default app assets (e.g., hospital.png) are added to the Frappe File DocType.
|
||||||
|
|
||||||
|
This makes the image available at '/files/hospital.png' and visible in Desk File List.
|
||||||
|
"""
|
||||||
|
files_to_setup = [
|
||||||
|
{
|
||||||
|
"file_name": "hospital.png",
|
||||||
|
"relative_path": ["public", "images", "hospital.png"],
|
||||||
|
"fallback_relative_path": ["public", "asm_app", "hospital.png"],
|
||||||
|
"is_private": 0,
|
||||||
|
"folder": "Home",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
for item in files_to_setup:
|
||||||
|
file_name = item["file_name"]
|
||||||
|
|
||||||
|
# 1. Check if the file already exists in File DocType
|
||||||
|
if frappe.db.exists("File", {"file_name": file_name}) or frappe.db.exists("File", {"file_url": f"/files/{file_name}"}):
|
||||||
|
continue
|
||||||
|
|
||||||
|
# 2. Locate the source file in app directory
|
||||||
|
source_path = frappe.get_app_path("asm_ui_app", *item["relative_path"])
|
||||||
|
if not os.path.exists(source_path) and "fallback_relative_path" in item:
|
||||||
|
source_path = frappe.get_app_path("asm_ui_app", *item["fallback_relative_path"])
|
||||||
|
|
||||||
|
if not os.path.exists(source_path):
|
||||||
|
frappe.logger().warning(f"[asm_ui_app] Source file not found for default file setup: {source_path}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
# 3. Read binary content
|
||||||
|
with open(source_path, "rb") as f:
|
||||||
|
file_content = f.read()
|
||||||
|
|
||||||
|
# 4. Create Frappe File document
|
||||||
|
# Setting is_private=0 and providing content automatically writes to sites/<site>/public/files/<file_name>
|
||||||
|
try:
|
||||||
|
file_doc = frappe.get_doc({
|
||||||
|
"doctype": "File",
|
||||||
|
"file_name": file_name,
|
||||||
|
"content": file_content,
|
||||||
|
"is_private": item.get("is_private", 0),
|
||||||
|
"folder": item.get("folder", "Home"),
|
||||||
|
})
|
||||||
|
file_doc.insert(ignore_permissions=True)
|
||||||
|
frappe.db.commit()
|
||||||
|
frappe.logger().info(f"[asm_ui_app] Successfully added default file '{file_name}' to File DocType.")
|
||||||
|
except Exception as e:
|
||||||
|
frappe.logger().error(f"[asm_ui_app] Failed to add default file '{file_name}' to File DocType: {e}")
|
||||||
BIN
asm_ui_app/public/asm_app/hospital.png
Normal file
BIN
asm_ui_app/public/asm_app/hospital.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 46 KiB |
BIN
asm_ui_app/public/images/hospital.png
Normal file
BIN
asm_ui_app/public/images/hospital.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 46 KiB |
Loading…
x
Reference in New Issue
Block a user