Skip to content

Commit 02f0212

Browse files
committed
upd
1 parent aa5d922 commit 02f0212

File tree

11 files changed

+327
-298
lines changed

11 files changed

+327
-298
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,16 @@ void loop() {
149149
150150
> Если нужно, чтобы параметр читался из БД, но нужно указать аргумент после него - значением нужно указать `Text()` как и сделано в функции по умолчанию. Например цвет для Label `b.Label(key, "Label!", Text(), sets::Colors::Mint);`. Если указать пустую строку (`b.Label(key, "Label!", "", sets::Colors::Mint);`) - в качестве значения и отправится пустая строка, т.е. значение не из БД.
151151
152+
> Указатель на текущий объект Settings внутри билдера или обработчика обновлений можно получить из `sets::thisSettings`
153+
152154
```cpp
153155
GyverDB db;
154156
SettingsGyver sett("My Settings", &db);
155157
156158
void build(sets::Builder& b) {
157159
b.Input("input1"_h, "Text");
160+
161+
// здесь sets::thisSettings - указатель на объект sett
158162
}
159163
160164
void setup() {

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Settings
2-
version=1.0.11
2+
version=1.0.12
33
author=AlexGyver <[email protected]>
44
maintainer=AlexGyver <[email protected]>
55
sentence=Simple UI webface builder for esp8266/esp32

src/SettingsBase.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <GyverDB.h>
55
#include <StringUtils.h>
66

7+
#include "core/SettingsBase_class.h"
78
#include "core/builder.h"
89
#include "core/colors.h"
910
#include "core/containers.h"
@@ -91,6 +92,7 @@ class SettingsBase {
9192
void parse(Text passh, Text action, Text idtxt, Text value) {
9293
size_t id = idtxt.toInt32HEX();
9394
bool granted = authenticate(passh);
95+
thisSettings = this;
9496

9597
switch (action.hash()) {
9698
case SH("discover"): {
@@ -178,6 +180,7 @@ class SettingsBase {
178180
}
179181
break;
180182
}
183+
thisSettings = nullptr;
181184
}
182185

183186
private:

src/core/SettingsBase_class.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "SettingsBase_class.h"
2+
3+
namespace sets {
4+
5+
SettingsBase* thisSettings = nullptr;
6+
7+
} // namespace sets

src/core/SettingsBase_class.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
3+
namespace sets {
4+
5+
class SettingsBase;
6+
7+
extern SettingsBase* thisSettings;
8+
9+
} // namespace sets

src/web/settings.h

Lines changed: 283 additions & 281 deletions
Large diffs are not rendered by default.

web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "settings",
3-
"version": "1.0.10",
3+
"version": "1.0.12",
44
"main": "index.js",
55
"scripts": {
66
"build": "webpack --config ./webpack.single.js & webpack --config ./webpack.index.js",

web/src/script/settings.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ export default class Settings {
7373
},
7474
{
7575
tag: 'div',
76-
class: 'icon bars',
76+
class: 'icon bars menubutton',
77+
var: 'menubutton',
7778
events: {
7879
click: async () => {
7980
iconFill(this.$ota, 'var(--font_tint)');
@@ -82,12 +83,14 @@ export default class Settings {
8283
this.$main_menu.classList.toggle('hidden');
8384
if (this.$main_menu.classList.contains('hidden')) {
8485
this.parse(await this.send('load'));
86+
this.$menubutton.classList = 'icon bars menubutton';
8587
} else {
8688
this.parse(await this.send('fs'));
89+
this.$menubutton.classList = 'icon cross menubutton';
8790
}
8891
},
8992
}
90-
}
93+
},
9194
]
9295
},
9396
{
@@ -124,15 +127,6 @@ export default class Settings {
124127
class: 'icon key',
125128
title: 'Auth',
126129
var: 'auth',
127-
events: {
128-
click: async () => {
129-
let res = await AsyncPrompt('Password', '');
130-
if (res !== null) {
131-
localStorage.setItem('auth', hash(res));
132-
window.location.reload();
133-
}
134-
},
135-
}
136130
}
137131
},
138132
{
@@ -366,6 +360,13 @@ export default class Settings {
366360
this.$ota.style.display = this.granted ? 'inline-block' : 'none';
367361
this.$upload.style.display = this.granted ? 'inline-block' : 'none';
368362
if (!this.granted && this.firstBuild) popup('Unauthorized');
363+
this.$auth.addEventListener('click', async () => {
364+
let res = await AsyncPrompt('Password', '');
365+
if (res !== null) {
366+
localStorage.setItem('auth', hash(res));
367+
window.location.reload();
368+
}
369+
});
369370
} else {
370371
this.$auth.style.backgroundColor = 'var(--font_tint)';
371372
this.granted = true;

web/src/script/widgets/widgets.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
overflow: hidden;
55
white-space: nowrap;
66
text-overflow: ellipsis;
7-
max-width: 80%;
7+
/* max-width: 80%; */
88
}
99

1010
.value.active {

web/src/style/icons.css

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
/* https://svgomg.net/ */
1414
/* https://yoksel.github.io/url-encoder/ */
1515
.icon.bars {
16-
--svg: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 448 512'%3E%3Cpath d='M0 96c0-18 14-32 32-32h384a32 32 0 1 1 0 64H32c-18 0-32-14-32-32zm0 160c0-18 14-32 32-32h384a32 32 0 1 1 0 64H32c-18 0-32-14-32-32zm448 160c0 18-14 32-32 32H32a32 32 0 1 1 0-64h384c18 0 32 14 32 32z'/%3E%3C/svg%3E");
17-
width: 22px;
18-
height: 25px;
16+
--svg: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M11 82c0-20 16-35 35-35h417a35 35 0 0 1 0 69H46c-19 0-35-15-35-34Zm0 173c0-19 16-34 35-34h417a35 35 0 0 1 0 69H46c-19 0-35-15-35-35Zm486 174c0 19-15 34-34 34H46a35 35 0 1 1 0-69h417c19 0 34 15 34 35Z'/%3E%3C/svg%3E");
1917
}
2018

2119
.icon.moon {

0 commit comments

Comments
 (0)