fix: preserve form values on error + rename Дата→Добавлена, Изменён→Изменена + bump 0.5.1
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ipwhitelist",
|
||||
"version": "0.5.0",
|
||||
"version": "0.5.1",
|
||||
"description": "IP WhiteList microservice for cloud provider",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
|
||||
+15
-3
@@ -76,6 +76,8 @@ function createRouter() {
|
||||
selectedCompany,
|
||||
error: req.query.error || null,
|
||||
success: req.query.success || null,
|
||||
lastValue: req.query.lastValue || '',
|
||||
lastComment: req.query.lastComment || '',
|
||||
csrfToken: '',
|
||||
});
|
||||
} catch (e) {
|
||||
@@ -84,7 +86,7 @@ function createRouter() {
|
||||
user: req.user, isAdmin: req.user.isAdmin,
|
||||
companies: [], selectedCompany: null,
|
||||
error: 'Ошибка загрузки: ' + e.message,
|
||||
success: null, csrfToken: '',
|
||||
success: null, lastValue: '', lastComment: '', csrfToken: '',
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -103,7 +105,12 @@ function createRouter() {
|
||||
: 'Запись добавлена';
|
||||
return res.redirect(back + (back.includes('?') ? '&' : '?') + 'success=' + encodeURIComponent(msg));
|
||||
}
|
||||
res.redirect(back + (back.includes('?') ? '&' : '?') + 'error=' + encodeURIComponent((r.data && r.data.error) || 'Ошибка'));
|
||||
// Ошибка — возвращаем введённые значения чтобы не перепечатывать
|
||||
const err = (r.data && r.data.error) || 'Ошибка';
|
||||
res.redirect(back + (back.includes('?') ? '&' : '?') +
|
||||
'error=' + encodeURIComponent(err) +
|
||||
'&lastValue=' + encodeURIComponent(value || '') +
|
||||
'&lastComment=' + encodeURIComponent(comment || ''));
|
||||
} catch (e) {
|
||||
res.redirect(back + (back.includes('?') ? '&' : '?') + 'error=' + encodeURIComponent(e.message));
|
||||
}
|
||||
@@ -120,7 +127,12 @@ function createRouter() {
|
||||
if (r.status === 200) {
|
||||
return res.redirect(back + (back.includes('?') ? '&' : '?') + 'success=' + encodeURIComponent('Запись обновлена'));
|
||||
}
|
||||
res.redirect(back + (back.includes('?') ? '&' : '?') + 'error=' + encodeURIComponent((r.data && r.data.error) || 'Ошибка'));
|
||||
// Ошибка — возвращаем введённые значения в модалку
|
||||
const err = (r.data && r.data.error) || 'Ошибка';
|
||||
res.redirect(back + (back.includes('?') ? '&' : '?') +
|
||||
'error=' + encodeURIComponent(err) +
|
||||
'&lastValue=' + encodeURIComponent(value || '') +
|
||||
'&lastComment=' + encodeURIComponent(comment || ''));
|
||||
} catch (e) {
|
||||
res.redirect(back + (back.includes('?') ? '&' : '?') + 'error=' + encodeURIComponent(e.message));
|
||||
}
|
||||
|
||||
+4
-4
@@ -245,11 +245,11 @@
|
||||
<div class="form-grid">
|
||||
<div class="field">
|
||||
<label>IPv4 адрес или подсеть CIDR</label>
|
||||
<input name="value" placeholder="Например: 203.0.113.10 или 203.0.113.0/24" pattern="^(\d{1,3}\.){3}\d{1,3}(/\d{1,2})?$" maxlength="18" title="IPv4 адрес или CIDR /22–/32" required <%= used >= limit ? 'disabled' : '' %>>
|
||||
<input name="value" placeholder="Например: 203.0.113.10 или 203.0.113.0/24" pattern="^(\d{1,3}\.){3}\d{1,3}(/\d{1,2})?$" maxlength="18" title="IPv4 адрес или CIDR /22–/32" value="<%= lastValue || '' %>" required <%= used >= limit ? 'disabled' : '' %>>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Комментарий</label>
|
||||
<input name="comment" placeholder="Необязательно" maxlength="255">
|
||||
<input name="comment" placeholder="Необязательно" maxlength="255" value="<%= lastComment || '' %>">
|
||||
</div>
|
||||
<button class="btn btn-primary" type="submit" <%= used >= limit ? 'disabled' : '' %> style="align-self:end">
|
||||
<%= used >= limit ? 'Лимит исчерпан' : 'Добавить' %>
|
||||
@@ -272,8 +272,8 @@
|
||||
<th>Адрес / Подсеть</th>
|
||||
<th>Комментарий</th>
|
||||
<th>Добавил</th>
|
||||
<th>Дата</th>
|
||||
<th>Изменён</th>
|
||||
<th>Добавлена</th>
|
||||
<th>Изменена</th>
|
||||
<th class="text-center">Действия</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
Reference in New Issue
Block a user