Skip to content

Commit

Permalink
settings view
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasLukasczyk committed Oct 8, 2024
1 parent ca2e642 commit 482a64b
Show file tree
Hide file tree
Showing 13 changed files with 199 additions and 56 deletions.
1 change: 0 additions & 1 deletion packages/main/src/DataHubService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ export const DataHubService = {
p++;
arcs = arcs.concat(arcs_page);
}
console.log(arcs.length)
return arcs;
},

Expand Down
16 changes: 11 additions & 5 deletions packages/main/src/InternetService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ const default_header = {

export const InternetService = {

getWebPageAsJson: (e,options): Promise<any> => {
getWebPageAsJson: async (e,options): Promise<any> => {
// check if server is available
try {
await net.resolveHost(options.host);
} catch(err) {
return new Promise((resolve,reject)=>resolve(null));
}

// get json data
return new Promise(
(resolve, reject) => {
try {
Expand All @@ -25,7 +33,7 @@ export const InternetService = {
for(let h in header)
request.setHeader(h,header[h]);

request.on('response', (response) => {
request.on('response', response => {
if(response.statusCode===200){
let output = '';
response.on('data', chunk => {
Expand All @@ -35,13 +43,11 @@ export const InternetService = {
resolve(JSON.parse(output));
});
} else {
// console.error('response',response);
resolve(null);
}
})
request.end()
} catch(err){
console.error('catch',err);
}catch(err){
resolve(null);
}
}
Expand Down
18 changes: 16 additions & 2 deletions packages/main/src/LocalFileSystemService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BrowserWindow, ipcMain, dialog, shell } from 'electron';
import { app, BrowserWindow, ipcMain, dialog, shell } from 'electron';
import PATH from 'path';
import FS from 'fs';
import FSE from 'fs-extra'
Expand Down Expand Up @@ -100,6 +100,18 @@ export const LocalFileSystemService = {
}
},

readConfig: ()=>{
const config = LocalFileSystemService.readFile(null,app.getPath('userData')+'/ARCitect.json');
return JSON.parse(config) || {};
},

writeConfig: (e,config)=>{
LocalFileSystemService.writeFile(null,[
app.getPath('userData')+'/ARCitect.json',
config
]);
},

readImage: async (e,path)=>{
try {
const contents = FS.readFileSync(path_to_system(path));
Expand Down Expand Up @@ -220,7 +232,7 @@ export const LocalFileSystemService = {
} catch {return false;}
},

remove: async (e,path)=>{
remove: (e,path)=>{
try {
FS.rmSync(path_to_system(path), {recursive:true,force:true});
return true;
Expand All @@ -246,6 +258,8 @@ export const LocalFileSystemService = {
ipcMain.handle('LocalFileSystemService.readDir', LocalFileSystemService.readDir);
ipcMain.handle('LocalFileSystemService.readFile', LocalFileSystemService.readFile);
ipcMain.handle('LocalFileSystemService.readImage', LocalFileSystemService.readImage);
ipcMain.handle('LocalFileSystemService.readConfig', LocalFileSystemService.readConfig);
ipcMain.handle('LocalFileSystemService.writeConfig', LocalFileSystemService.writeConfig);
ipcMain.handle('LocalFileSystemService.enforcePath', LocalFileSystemService.enforcePath);
ipcMain.handle('LocalFileSystemService.writeFile', LocalFileSystemService.writeFile);
ipcMain.handle('LocalFileSystemService.selectDir', LocalFileSystemService.selectDir);
Expand Down
29 changes: 18 additions & 11 deletions packages/main/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ app.on('window-all-closed', () => {
*/
app.on('activate', restoreOrCreateWindow);

const initConfig = async ()=>{
const userDataPath = app.getPath('userData');
if(!fs.existsSync(userDataPath))
fs.mkdirSync(userDataPath);

for(let file of ['ARCitect.json','DataHubs.json']){
const sourceFile = 'resources/'+file;
const destinationFile = userDataPath+'/'+file;
if (!fs.existsSync(destinationFile))
fs.copyFileSync(sourceFile, destinationFile);
}
};

const initCore = async () => {
const PATH = require('path');
if(process.platform === 'win32'){
Expand All @@ -55,17 +68,11 @@ const initCore = async () => {
}
ipcMain.handle('CORE.getVersion', ()=>app.getVersion());
ipcMain.handle('CORE.getTempPath', ()=>app.getPath('temp'));

const userDataPath = app.getPath('userData');
if(!fs.existsSync(userDataPath))
fs.mkdirSync(userDataPath);

for(let file of ['ARCitect.json','DataHubs.json']){
const sourceFile = 'resources/'+file;
const destinationFile = userDataPath+'/'+file;
if (!fs.existsSync(destinationFile))
fs.copyFileSync(sourceFile, destinationFile);
}
ipcMain.handle('CORE.reset', ()=>{
LocalFileSystemService.remove( null, app.getPath('userData') );
initConfig();
});
initConfig();
}

/**
Expand Down
20 changes: 9 additions & 11 deletions packages/renderer/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import GitHistoryView from './views/GitHistoryView.vue';
import SwateView from './views/SwateView.vue';
import ValidationView from './views/ValidationView.vue';
import StatusView from './views/StatusView.vue';
import SettingsView from './views/SettingsView.vue';
import ConfirmationDialog from './dialogs/ConfirmationDialog.vue';
import GitDialog from './dialogs/GitDialog.vue';
Expand Down Expand Up @@ -43,7 +44,6 @@ const $q = useQuasar();
const iProps = reactive({
showToolbar: true,
toolbarMinimized: false,
splitterModel: 300,
error: false,
error_text: '',
Expand Down Expand Up @@ -131,7 +131,6 @@ const showHomeView = ()=>{
};
const messagePrompt = msg => {
console.log(msg);
$q.dialog({
component: ConfirmationDialog,
componentProps: {
Expand Down Expand Up @@ -184,7 +183,7 @@ const test = async ()=>{
v-model='iProps.showToolbar'
show-if-above

:mini="iProps.toolbarMinimized"
:mini="AppProperties.config.toolbarMinimized"

:width="190"
:breakpoint="500"
Expand Down Expand Up @@ -257,13 +256,10 @@ const test = async ()=>{
<ToolbarButton text='Services' :icon='Object.values(AppProperties.datahub_hosts_msgs).some(x=>x.critical)?"warning":"dns"' @clicked='AppProperties.state=AppProperties.STATES.STATUS;'>
<a_tooltip>Check on the status of <b>nfdi4plants</b> services</a_tooltip>
</ToolbarButton>
<ToolbarButton text='Toggle Help' icon='help' @clicked='AppProperties.showHelp=!AppProperties.showHelp;'>
<a_tooltip>Show or hide the help menu</a_tooltip>
<ToolbarButton text='Settings' icon='settings' @clicked='AppProperties.state=AppProperties.STATES.SETTINGS;'>
<a_tooltip>Modify ARCitect settings</a_tooltip>
</ToolbarButton>
<ToolbarButton text='Toggle Tooltips' :icon='AppProperties.showTooltips? "sym_r_mark_chat_read":"sym_r_chat_bubble" ' @clicked='AppProperties.showTooltips=!AppProperties.showTooltips;'>
<a_tooltip>Show or hide tooltips</a_tooltip>
</ToolbarButton>
<ToolbarButton :text="iProps.toolbarMinimized ? '' : 'Toggle Sidebar'" :icon="iProps.toolbarMinimized ? 'chevron_right' : 'chevron_left'" @clicked='iProps.toolbarMinimized=!iProps.toolbarMinimized;'></ToolbarButton>
<ToolbarButton :text="AppProperties.config.toolbarMinimized ? '' : 'Toggle Sidebar'" :icon="AppProperties.config.toolbarMinimized ? 'chevron_right' : 'chevron_left'" @clicked='AppProperties.config.toolbarMinimized=!AppProperties.config.toolbarMinimized;'></ToolbarButton>
<q-separator />

<q-item v-ripple clickable dense @click='downloadArcitect'>
Expand All @@ -280,14 +276,14 @@ const test = async ()=>{
</q-drawer>

<q-drawer
v-model="AppProperties.showHelp"
v-model="AppProperties.config.showHelp"
side="right"
bordered
:breakpoint='0'
class="bg-grey-3"
:width="400"
>
<q-btn style="position:absolute;right:0em; top:0.6em; z-index:9999" icon="chevron_right" flat round @click='AppProperties.showHelp=false' />
<q-btn style="position:absolute;right:0em; top:0.6em; z-index:9999" icon="chevron_right" flat round @click='AppProperties.config.showHelp=false' />
<q-scroll-area class='fit' style="height: 100%;width:100%;">
<HelpView></HelpView>
</q-scroll-area>
Expand All @@ -307,6 +303,7 @@ const test = async ()=>{
</q-scroll-area>
</template>


<template v-slot:after>
<q-dialog v-model="iProps.error">
<q-card>
Expand Down Expand Up @@ -339,6 +336,7 @@ const test = async ()=>{
<SwateView v-else-if='AppProperties.state===AppProperties.STATES.EDIT_SWATE'></SwateView>
<ValidationView v-else-if='AppProperties.state===AppProperties.STATES.VALIDATION'></ValidationView>
<StatusView v-else-if='AppProperties.state===AppProperties.STATES.STATUS'></StatusView>
<SettingsView v-else-if='AppProperties.state===AppProperties.STATES.SETTINGS'></SettingsView>
<HomeView v-else></HomeView>
</template>
</q-splitter>
Expand Down
56 changes: 46 additions & 10 deletions packages/renderer/src/AppProperties.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { reactive } from 'vue'
import { reactive, watch } from 'vue'

const AppProperties: {
STATES: any,
Expand All @@ -19,20 +19,33 @@ const AppProperties: {

VALIDATION: 700,
STATUS: 800,
SETTINGS: 900,
},
STATES_I: {},
state: 0,

user: null,


datahub_hosts : [],
datahub_hosts_msgs: {},

force_commit_update: 0,
force_lfs_update: 0,

showHelp: false,
showTooltips: false
config: {
toolbarMinimized: false,
showHelp: false,
showTooltips: false,
swate_url: ''
},

read_config: async ()=>{
const config = await window.ipc.invoke('LocalFileSystemService.readConfig');
for(let key of Object.keys(config)){
AppProperties.config[key] = config[key];
}
}
});

for(let k in AppProperties.STATES){
Expand All @@ -48,16 +61,39 @@ const get_datahubs = async ()=>{
path: '/api/v4/broadcast_messages',
method: 'GET'
});
let contains_critical = false;
for(let msg of AppProperties.datahub_hosts_msgs[host]){
const t = msg.message.toLowerCase();
msg.critical = t.includes('maintenance') || t.includes('downtime');
contains_critical = contains_critical || (msg.critical && msg.active);

// if server is not reachable
if(AppProperties.datahub_hosts_msgs[host]===null){
const temp = [];
temp.critical = true;
temp.push({
message: 'Server Not Reachable',
critical: true,
active: true,
starts_at: new Date().toISOString()
})
console.log(new Date().toISOString())
AppProperties.datahub_hosts_msgs[host] = temp;
} else {
let contains_critical = false;
for(let msg of AppProperties.datahub_hosts_msgs[host]){
const t = msg.message.toLowerCase();
msg.critical = t.includes('maintenance') || t.includes('downtime');
contains_critical = contains_critical || (msg.critical && msg.active);
}
AppProperties.datahub_hosts_msgs[host].critical = contains_critical;
}
AppProperties.datahub_hosts_msgs[host].critical = contains_critical;
}
};

get_datahubs();
const init = async ()=>{
await AppProperties.read_config();
watch(AppProperties.config, ()=>{
console.log('xxx')
window.ipc.invoke('LocalFileSystemService.writeConfig', JSON.stringify(AppProperties.config));
});
await get_datahubs();
}
init();

export default AppProperties;
8 changes: 2 additions & 6 deletions packages/renderer/src/components/ViewItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
export interface Props {
label: String,
caption: String,
icon: String,
fullWidth?: Boolean,
icon: String
};
const props = defineProps<Props>();
Expand All @@ -27,10 +26,7 @@ const props = defineProps<Props>();
</q-item-section>
</template>

<div v-if='props.fullWidth' style="display:block;margin:0 auto;border-top:1px solid #ccc;">
<slot></slot>
</div>
<div v-else style="display:block;margin:0 auto;max-width:700px;border-top:1px solid #ccc;">
<div style="display:block;margin:0 auto;border-top:1px solid #ccc;">
<slot></slot>
</div>
</q-expansion-item>
Expand Down
2 changes: 1 addition & 1 deletion packages/renderer/src/components/a_tooltip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import AppProperties from '../AppProperties.ts';
</script>

<template>
<q-tooltip v-if='AppProperties.showTooltips' style="font-size:1.1em">
<q-tooltip v-if='AppProperties.config.showTooltips' style="font-size:1.1em">
<slot></slot>
</q-tooltip>
</template>
1 change: 0 additions & 1 deletion packages/renderer/src/views/DataHubView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ const host_manually_set = ()=>{
icon="cloud_download"
label="Download ARC"
caption="Download ARCs from the nfdi4plants DataHUB"
:fullWidth="false"
>
<br>
<div class="q-gutter-md row q-px-md">
Expand Down
Loading

0 comments on commit 482a64b

Please sign in to comment.