Browse Source

added option to remove template

lllllllillllllillll 1 year ago
parent
commit
5081100f71
5 changed files with 25 additions and 7 deletions
  1. 1 1
      CHANGELOG.md
  2. 3 3
      README.md
  3. 18 2
      controllers/apps.js
  4. 2 1
      router/index.js
  5. 1 0
      views/apps.html

+ 1 - 1
CHANGELOG.md

@@ -1,4 +1,4 @@
-## v0.60 (dev)
+## v0.60 (May 19th 2024)
 * Converted JS template literals into HTML.
 * Converted modals into HTML/HTMX.
 * Moved functions into dashboard controller.

+ 3 - 3
README.md

@@ -20,15 +20,15 @@
 * DweebUI is a management interface and should not be directly exposed to the internet
 
 ## Features
-* [x] A dynamically updating dashboard that displays server metrics along with individual container metrics and container controls.
-* [x] Multi-users with permissions system.
+* [x] A dynamically updating dashboard that displays server metrics along with container metrics and container controls.
+* [x] Multi-user support with permissions system.
 * [x] View container logs.
 * [x] Manage your Docker networks, images, and volumes.
 * [x] Light/Dark Mode.
 * [x] Mobile Friendly.
 * [x] Easy to install app templates.
 * [x] Windows, Linux, and MacOS compatable.
-* [ ] Docker compose (in development).
+* [x] Docker Compose Support.
 * [ ] Update containers (planned).
 * [x] Templates.json maintains compatability with Portainer, allowing you to use the template without needing to use DweebUI.
 * [ ] Preset variables (planned).

+ 18 - 2
controllers/apps.js

@@ -11,12 +11,19 @@ const upload = multer({storage: multer.diskStorage({
 let alert = '';
 let templates_global = '';
 let json_templates = '';
+let remove_button = '';
 
 export const Apps = async (req, res) => {
   
   let page = Number(req.params.page) || 1;
   let template_param = req.params.template || 'default';
 
+  if ((template_param != 'default') && (template_param != 'compose')) {
+    remove_button = `<a href="/remove_template/${template_param}" class="btn" hx-confirm="Are you sure you want to remove this template?">Remove</a>`;
+  } else {
+    remove_button = '';
+  }
+
   json_templates = '';
   let json_files = readdirSync('templates/json/');
   for (let i = 0; i < json_files.length; i++) {
@@ -126,14 +133,22 @@ export const Apps = async (req, res) => {
     template_list: '',
     json_templates: json_templates,
     pages: pages,
+    remove_button: remove_button
   });
   alert = '';
 }
 
-
+export const removeTemplate = async (req, res) => {
+  let template = req.params.template;
+  unlinkSync(`templates/json/${template}.json`);
+  res.redirect('/apps');
+}
 
 
 export const appSearch = async (req, res) => {
+
+  let search = req.body.search;
+
   let page = Number(req.params.page) || 1;
 
   let template_param = req.params.template || 'default';
@@ -161,7 +176,6 @@ export const appSearch = async (req, res) => {
   if (page == 1) { prev = '/apps/' + (page); }
   if (page == last_page) { next = '/apps/' + (page); }
 
-  let search = req.body.search;
 
   let apps_list = '';
   let results = [];
@@ -209,6 +223,7 @@ export const appSearch = async (req, res) => {
     appCard = appCard.replace(/AppDesc/g, desc);
     appCard = appCard.replace(/AppLogo/g, logo);
     appCard = appCard.replace(/AppCategories/g, categories);
+    appCard = appCard.replace(/AppType/g, 'json');
 
     apps_list += appCard;
   }
@@ -226,6 +241,7 @@ export const appSearch = async (req, res) => {
       template_list: '',
       json_templates: json_templates,
       pages: pages,
+      remove_button: remove_button
   });
 }
 

+ 2 - 1
router/index.js

@@ -6,7 +6,7 @@ export const router = express.Router();
 import { Login, submitLogin, Logout } from "../controllers/login.js";
 import { Register, submitRegister } from "../controllers/register.js";
 import { Dashboard, DashboardAction, Stats, Chart, SSE, UpdatePermissions } from "../controllers/dashboard.js";
-import { Apps, appSearch, InstallModal, ImportModal, LearnMore, Upload } from "../controllers/apps.js";
+import { Apps, appSearch, InstallModal, ImportModal, LearnMore, Upload, removeTemplate } from "../controllers/apps.js";
 import { Users } from "../controllers/users.js";
 import { Images } from "../controllers/images.js";
 import { Networks, removeNetwork } from "../controllers/networks.js";
@@ -85,6 +85,7 @@ router.post("/removeNetwork", adminOnly, removeNetwork);
 
 router.get("/apps/:page?/:template?", adminOnly, Apps);
 router.post("/apps", adminOnly, appSearch);
+router.get("/remove_template/:template", adminOnly, removeTemplate);
 
 router.get("/install_modal", adminOnly, InstallModal)
 router.get("/import_modal", adminOnly, ImportModal)

+ 1 - 0
views/apps.html

@@ -36,6 +36,7 @@
                   <div class="card-body text-center">
                     <div class="d-flex align-items-center">
                       <div class="me-auto btn"><%= list_start %> - <%= list_end %> of <%= app_count %> Apps</div>
+                        <%- remove_button %>
                     </div>
                   </div>
                 </div>