From db82f8564c54ecd7dbaa5538078c5c7c640a334d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Berthaud-M=C3=BCller?= Date: Fri, 29 Apr 2022 04:33:00 +0200 Subject: [PATCH] fix indentation --- public/scripts/api.js | 20 ++--- public/scripts/records.js | 144 ++++++++++++++++++------------------ public/styles/main.css | 36 ++++----- src/template.rs | 60 +++++++-------- templates/base.html | 12 +-- templates/login.html | 24 +++--- templates/zone/records.html | 14 ++-- 7 files changed, 155 insertions(+), 155 deletions(-) diff --git a/public/scripts/api.js b/public/scripts/api.js index f97f9df..f142d02 100644 --- a/public/scripts/api.js +++ b/public/scripts/api.js @@ -2,21 +2,21 @@ const baseUrl = '/api/v1'; function apiGet(url) { - return fetch(`${baseUrl}/${url}`) - .then(res => { - if (!res.ok) { - // do something here - throw new Error('Not ok'); - } - return res.json(); - }) + return fetch(`${baseUrl}/${url}`) + .then(res => { + if (!res.ok) { + // do something here + throw new Error('Not ok'); + } + return res.json(); + }) } function getRecords(zone) { - return apiGet(`zones/${zone}/records`) + return apiGet(`zones/${zone}/records`) } export { - getRecords, + getRecords, }; diff --git a/public/scripts/records.js b/public/scripts/records.js index be2e6ba..8b36373 100644 --- a/public/scripts/records.js +++ b/public/scripts/records.js @@ -2,99 +2,99 @@ import { html, Component, render, createContext, useState, useEffect } from 'htt import { getRecords } from './api.js'; const rdataInputProperties = { - Address: {label: 'adresse', type: 'text'}, - Serial: {label: 'serial', type: 'number'}, - Minimum: {label: 'minimum', type: 'number'}, - Retry: {label: 'nouvelle tentative', type: 'number'}, - Refresh: {label: 'actualisation', type: 'number'}, - MaintainerName: {label: 'contact', type: 'text'}, - MasterServerName: {label: 'serveur primaire', type: 'text'}, - Expire: {label: 'expiration', type: 'number'}, - Target: {label: 'cible', type: 'text'}, + Address: {label: 'adresse', type: 'text'}, + Serial: {label: 'serial', type: 'number'}, + Minimum: {label: 'minimum', type: 'number'}, + Retry: {label: 'nouvelle tentative', type: 'number'}, + Refresh: {label: 'actualisation', type: 'number'}, + MaintainerName: {label: 'contact', type: 'text'}, + MasterServerName: {label: 'serveur primaire', type: 'text'}, + Expire: {label: 'expiration', type: 'number'}, + Target: {label: 'cible', type: 'text'}, } const Editable = createContext(false); function RDataInput({ name, value = '', index = 0 }) { - const {label, type} = rdataInputProperties[name] || {label: name, type: 'text'}; + const {label, type} = rdataInputProperties[name] || {label: name, type: 'text'}; - return html` - <${Editable.Consumer}> - ${ - (editable) => { - if (editable) { - return html` -
- - -
- `; - } else { - return html` -
- ${label}: - ${value} -
- ` - } - } - } - - `; + return html` + <${Editable.Consumer}> + ${ + (editable) => { + if (editable) { + return html` +
+ + +
+ `; + } else { + return html` +
+ ${label}: + ${value} +
+ ` + } + } + } + + `; } function RData({ rdata, index }) { - const { Address: address } = rdata; - return Object.entries(rdata).map(([name, value]) => html`<${RDataInput} name=${name} value=${value} index=${index} />`); + const { Address: address } = rdata; + return Object.entries(rdata).map(([name, value]) => html`<${RDataInput} name=${name} value=${value} index=${index} />`); } function Record({name, ttl, type, rdata, index = 0}) { - return html` - - ${name} - ${type} - ${ttl} - <${RData} rdata=${rdata} index=${index}/> - - `; + return html` + + ${name} + ${type} + ${ttl} + <${RData} rdata=${rdata} index=${index}/> + + `; } function RecordList({ zone }) { - const [records, setRecords] = useState([]); - const [editable, setEditable] = useState(false); + const [records, setRecords] = useState([]); + const [editable, setEditable] = useState(false); - const toggleEdit = () => setEditable(!editable); + const toggleEdit = () => setEditable(!editable); - useEffect(() => { - getRecords(zone) - .then((res) => setRecords(res)); - }, []) + useEffect(() => { + getRecords(zone) + .then((res) => setRecords(res)); + }, []) - return html` - <${Editable.Provider} value=${editable}> - - - - - - - - - - - - ${records.map( - ({Name, Class, TTL, Type, ...rdata}, index) => { - return html`<${Record} name=${Name} ttl=${TTL} type=${Type} rdata=${rdata} index=${index}/>` - } - )} - - - - `; + return html` + <${Editable.Provider} value=${editable}> + +
NomTypeTTLDonnées
+ + + + + + + + + + ${records.map( + ({Name, Class, TTL, Type, ...rdata}, index) => { + return html`<${Record} name=${Name} ttl=${TTL} type=${Type} rdata=${rdata} index=${index}/>` + } + )} + + + + `; } export { RecordList }; diff --git a/public/styles/main.css b/public/styles/main.css index 8491bfc..54e9aa5 100644 --- a/public/styles/main.css +++ b/public/styles/main.css @@ -1,41 +1,41 @@ body { - color: #2e2033; + color: #2e2033; } .record-list { - border-collapse: collapse; + border-collapse: collapse; } .record-list .rdata { - display: flex; - flex-wrap: wrap; + display: flex; + flex-wrap: wrap; } .record-list th, .record-list td { - font-weight: normal; - text-align: left; - vertical-align: top; - padding: 0.25rem; + font-weight: normal; + text-align: left; + vertical-align: top; + padding: 0.25rem; } .record-list thead { - background: #ccb9ff; - color: #39004d; + background: #ccb9ff; + color: #39004d; } .record-list tbody tr:nth-child(even) td { - background: #ccb9ff3d; + background: #ccb9ff3d; } .record-list tbody tr .rdata span.label, .record-list tbody tr .rdata label { - display: inline-block; - padding: 0.1em 0.5em; - background: #cecece; - font-size: 0.7rem; - border-radius: 0.5em; - margin-right: 0.1rem; + display: inline-block; + padding: 0.1em 0.5em; + background: #cecece; + font-size: 0.7rem; + border-radius: 0.5em; + margin-right: 0.1rem; } .record-list tbody tr .rdata > div { - margin: 0.1rem 0.5rem 0.1rem 0; + margin: 0.1rem 0.5rem 0.1rem 0; } diff --git a/src/template.rs b/src/template.rs index 3cb17dc..0e0a9a9 100644 --- a/src/template.rs +++ b/src/template.rs @@ -10,48 +10,48 @@ use tera::{Tera, Context}; pub struct TemplateState { - tera: Tera, + tera: Tera, } impl TemplateState { - pub fn new(template_directory: &Path) -> Self { - let template_glob = template_directory.join("**").join("*"); - match Tera::new(template_glob.to_str().expect("valid glob path string")) { - Ok(tera) => TemplateState { tera }, - Err(e) => { - println!("Loading templates failed: {}", e); - exit(1) - } - } - } + pub fn new(template_directory: &Path) -> Self { + let template_glob = template_directory.join("**").join("*"); + match Tera::new(template_glob.to_str().expect("valid glob path string")) { + Ok(tera) => TemplateState { tera }, + Err(e) => { + println!("Loading templates failed: {}", e); + exit(1) + } + } + } } pub struct Template<'t, S: Serialize> { - pub name: &'t str, - pub context: S, + pub name: &'t str, + pub context: S, } impl<'r, S: Serialize> Template<'r, S> { - pub fn new(name: &'r str, context: S) -> Self { - Template { - name, - context - } - } + pub fn new(name: &'r str, context: S) -> Self { + Template { + name, + context + } + } - fn render(self, tera: &Tera) -> Result<(ContentType, String), Status> { - let context = Context::from_serialize(self.context).map_err(|e| { - error!("Failed to serialize context: {}", e); - Status::InternalServerError - })?; + fn render(self, tera: &Tera) -> Result<(ContentType, String), Status> { + let context = Context::from_serialize(self.context).map_err(|e| { + error!("Failed to serialize context: {}", e); + Status::InternalServerError + })?; - let content = tera.render(self.name, &context).map_err(|e| { - error!("Failed to render template `{}`: {}", self.name, e); - Status::InternalServerError - })?; + let content = tera.render(self.name, &context).map_err(|e| { + error!("Failed to render template `{}`: {}", self.name, e); + Status::InternalServerError + })?; - Ok((ContentType::HTML, content)) - } + Ok((ContentType::HTML, content)) + } } impl<'r, 't, S: Serialize> Responder<'r, 'static> for Template<'t, S> { diff --git a/templates/base.html b/templates/base.html index 632ab4f..98dfe72 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,13 +1,13 @@ - - - {% block title %}{% endblock title %}Nomilo - + + + {% block title %}{% endblock title %}Nomilo + - {% block content %}{% endblock content %} - {% block scripts %}{% endblock scripts %} + {% block content %}{% endblock content %} + {% block scripts %}{% endblock scripts %} diff --git a/templates/login.html b/templates/login.html index 7c241c4..f6f65f8 100644 --- a/templates/login.html +++ b/templates/login.html @@ -3,16 +3,16 @@ {% block title %}Login ⋅ {% endblock title %} {% block content %} -
- {% if error %} -

- {{ error }} -

- {% endif %} -
- - - - -
+
+ {% if error %} +

+ {{ error }} +

+ {% endif %} +
+ + + + +
{% endblock content %} diff --git a/templates/zone/records.html b/templates/zone/records.html index 2f34bba..f9f1c21 100644 --- a/templates/zone/records.html +++ b/templates/zone/records.html @@ -3,16 +3,16 @@ {% block title %}{{ zone }} ⋅ Records ⋅ {% endblock title %} {% block content %} -
+
{% endblock content %} {% block scripts %} - + render(html`<${RecordList} zone=${zoneName} />`, document.querySelector('main')); + {% endblock scripts %}
NomTypeTTLDonnées