add plugin settings page

This commit is contained in:
2023-08-30 17:17:06 +02:00
parent f0d433a0eb
commit 6ea687fa47
10 changed files with 111 additions and 27 deletions

View File

@@ -100,6 +100,8 @@ class GETHandler {
} );
} else if ( call === 'getSettings' ) {
resolve( this.settings );
} else if ( call === 'getAllPlugins' ) {
resolve( this.pluginManager.getPlugins() );
} else {
reject( { 'code': 404, 'error': 'Route not found' } );
}

View File

@@ -144,7 +144,11 @@ class POSTHandler {
} );
resolve( 'ok' );
} else if ( call === 'updatePaymentGatewaySettings' ) {
resolve( 'ok' );
this.pluginManager.savePaymentGatewaySettings( data ).then( () => {
resolve( 'ok' );
} ).catch( err => {
reject( { 'code': 500, 'message': err } );
} );
} else {
reject( { 'code': 404, 'error': 'Route not found' } );
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

View File

@@ -2,4 +2,4 @@
If you want to create a new plugin for libreevent, please follow our guide and guidelines in the official documentation [here](https://libreevent.janishutz.com/docs/contributing/plugins)
Each plugin should have a plugin.json file that uses the layout of the plugin.json file in this directory. As future libreevent might change what is required by the plugin.json file, please follow this repository to get news when this is about to happen. To retain backwards compatibility, we will for as long as possible not remove anything from the plugin.json files as possible, which means you can already update your plugin.json file before the next version of libreevent is released.
Each plugin should have a plugin.json file that uses the layout of the plugin.json file in this directory. As future libreevent might change what is required by the plugin.json file, please follow this repository to get news when this is about to happen. To retain backwards compatibility, we will for as long as possible not remove anything from the plugin.json files as possible, which means you can already update your plugin.json file before the next version of libreevent is released. The plugin.json file already contains a "mainPluginURL" parameter which currently is not in use.

View File

@@ -17,26 +17,17 @@ const path = require( 'path' );
class PluginManager {
constructor ( settings ) {
this.paymentGateway = settings.payments;
this.allPlugins = {};
this.pluginDetails = {};
fs.readdir( path.join( __dirname + '/others' ), ( err, ls ) => {
for ( let file in ls ) {
const pluginSettings = JSON.parse( fs.readFileSync( path.join( __dirname + '/others/' + ls[ file ] + '/plugin.json' ) ) );
this.allPlugins[ ls[ file ] ] = pluginSettings;
const pluginDetail = JSON.parse( fs.readFileSync( path.join( __dirname + '/others/' + ls[ file ] + '/plugin.json' ) ) );
this.pluginDetails[ ls[ file ] ] = pluginDetail;
}
} );
}
getPlugins () {
}
getPluginDetails ( plugin ) {
return new Promise( ( resolve, reject ) => {
fs.readFile( path.join( __dirname + '/others/' + plugin + '/plugin.json' ), ( err, file ) => {
if ( err ) reject( err );
resolve( file );
} );
} );
return this.pluginDetails;
}
loadPaymentGatewaySettings () {
@@ -63,15 +54,14 @@ class PluginManager {
} );
}
savePaymentGatewaySettings () {
savePaymentGatewaySettings ( settings ) {
return new Promise( ( resolve, reject ) => {
fs.writeFile( path.join( __dirname + '/payments/' + this.paymentGateway + '/config.payments.json' ), JSON.stringify( settings ), {}, ( err ) => {
if ( err ) reject( err );
resolve( 'ok' );
} );
} );
}
saveSettings ( plugin, settings ) {
}
}
module.exports = PluginManager;

View File

@@ -6,7 +6,8 @@
"pluginWebsite": "https://libreevent.janishutz.com/plugins/newsletter",
"pluginDocs": "https://libreevent.janishutz.com/docs/plugins/newsletter",
"gitURL": "https://github.com/simplePCBuilding/libreevent/tree/master/src/server/backend/plugins/others/newsletter",
"settingsURL": "/admin/plugins/newsletter/settings",
"settingsURL": "/admin/plugins/newsletter",
"mainPluginURL": "/admin/plugins/newsletter",
"logo": "",
"version": "1.0.0"
}

View File

@@ -8,5 +8,6 @@
"gitURL": "https://github.com/simplePCBuilding/libreevent/tree/master/src/server/backend/plugins/others/poll",
"settingsURL": "/admin/plugins/polls/settings",
"mainPluginURL": "/polls",
"logo": "",
"version": "1.0.0"
}

View File

@@ -8,5 +8,6 @@
"gitURL": "",
"settingsURL": "",
"mainPluginURL": "",
"logo": "",
"version": ""
}