File size: 3,626 Bytes
27867f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
"""
MIT License

Copyright (C) 2023 ROCKY4546
https://github.com/rocky4546

This file is part of Cabernet

Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the “Software”), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
"""

from lib.common.decorators import getrequest


@getrequest.route('/api/plugins')
def get_plugins_html(_webserver):
    plugins_html = PluginsHTML()
    html = plugins_html.get()
    _webserver.do_mime_response(200, 'text/html', html)


class PluginsHTML:

    def __init__(self):
        self.config = None
        self.active_tab_name = None
        self.tab_names = None

    def get(self):
        self.tab_names = self.get_tabs()
        return ''.join([self.header, self.body])

    @property
    def header(self):
        return ''.join([
            '<!DOCTYPE html><html><head>',
            '<meta charset="utf-8"/><meta name="author" content="rocky4546">',
            '<meta name="description" content="Cabernet Plugins">',
            '<title>Plugins</title>',
            '<meta name="viewport" content="width=device-width, ',
            'minimum-scale=1.0, maximum-scale=1.0">',
            '<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>',
            '<link rel="stylesheet" type="text/css" href="/modules/tabs/tabs.css">',
            '<link rel="stylesheet" type="text/css" href="/modules/pluginmgr/pluginmgrform.css">',
            '<script src="/modules/tabs/tabs.js"></script>',
            '<script src="/modules/pluginmgr/pluginmgr.js"></script></head>',
            '<script src="/modules/pluginmgr/pluginmgrform.js"></script>'
            '<script src="/modules/listview/menu.js"></script>'
        ])

    @property
    def title(self):
        return ''.join([
            '<div class="container">',
            '<h2>Plugins</h2>'
        ])

    @property
    def tabs(self):
        activeTab = 'activeTab'
        tabs_html = ''.join([
            '<ul class="tabs">'])
        for name, icon in self.tab_names.items():
            key = name.replace(' ', '_')
            tabs_html = ''.join([
                tabs_html,
                '<li><a id="tab', name, '" class="form',
                name, ' configTab ',
                activeTab,
                '" href="#" onclick=\'load_form_url("/api/pluginsform?area=',
                key, '")\'>',
                '<i class="md-icon tabIcon">',
                icon,
                '</i>',
                name, '</a></li>'
            ])
            activeTab = ''
            self.active_tab_name = name
        tabs_html = ''.join([tabs_html, '</ul>'])
        return tabs_html

    @property
    def body(self):
        return ''.join([
            '<body>',
            self.title,
            self.tabs,
            '<div id="pluginscontent" class="pluginShow">',
            '<script>load_form_url("/api/pluginsform?area=My_Plugins")</script></div>',
            self.plugin_page
        ])

    @property
    def plugin_page(self):
        return ''.join([
            '<div id="plugincontent" class="pluginHide"></div>'
        ])



    def get_tabs(self):
        return {'My Plugins': 'extension', 'Catalog': 'add_shopping_cart'}