La Bureautique refactorise ta mère

This commit is contained in:
Boris 2022-10-31 20:12:51 +01:00
parent 00534c42f0
commit c7c6598a52
18 changed files with 494 additions and 35 deletions

View File

@ -10,3 +10,6 @@ sudo apt install python3-gpg python3-jwcrypto
python3 -m pip install -U pgpy pynentry SecureBytes
```
```
sudo vendor/jaklis/setup.sh
```

View File

@ -85,9 +85,10 @@ $games = [
]
];
$radiuses = [5, 10, 20, 50];
$radiuses = [5, 10, 20, 50, 100];
define('DEFAULT_GAME', 'spationaute');
define('GAME_JS_DIR', 'themes/'. $_SESSION['gameId'] . '/js/map');
if (!isset($_SESSION['gameId'])) {
@ -98,6 +99,10 @@ if (!isset($_SESSION['gameId'])) {
define('DEFAULT_WEBPAGE_TITLE', 'La bureautique');
$javascripts = [
'header' => [],
'footer' => []
];
require_once('functions.php');

23
farfetched.php Normal file
View File

@ -0,0 +1,23 @@
<?php
require_once('config.php');
require_once('lib/Gchange.class.php');
$gchange = new Gchange();
$javascripts['header'][] = 'lib/js/farfetched.js';
include_once('header.php');
?>
<h2>Envoi possible</h2>
<ul id="shippable">
</ul>
<h2>Offres immatérielles</h2>
<ul id="immaterial">
</ul>
<?php
include_once('footer.php');

View File

@ -5,22 +5,28 @@
</footer>
<?php
if (isset($_SESSION['gameId']) and isset($bodyIds) and strpos($bodyIds, 'startpage') === false) {
$themeJSDir = 'themes/'. $_SESSION['gameId'] . '/js';
$files = scandir($themeJSDir);
$files = array_slice($files, 2);
// if (isset($_SESSION['gameId']) and ((isset($bodyIds) and strpos($bodyIds, 'startpage') === false)) or (!isset($bodyIds))) {
foreach ($files as $f) {
// $themeJSDir = 'themes/'. $_SESSION['gameId'] . '/js';
// $files = scandir($themeJSDir);
// $files = array_slice($files, 2);
echo '
<script type="text/javascript" src="'. $themeJSDir . '/' . $f .'"></script>
';
}
// foreach ($files as $f) {
// echo '
// <script type="text/javascript" src="'. $themeJSDir . '/' . $f .'"></script>
// ';
// }
// }
foreach ($javascripts['footer'] as $js) {
echo '
<script src="'. $js . '"></script>
';
}
?>
<script type="text/javascript" src="assets/js/places.js"></script>
</body>
</html>

View File

@ -8,7 +8,7 @@ $webpageTitle = isset($webpageTitle) ? $webpageTitle : DEFAULT_WEBPAGE_TITLE;
<title><?php echo $webpageTitle; ?></title>
<?php
if (isset($_SESSION['gameId']) and isset($bodyIds) and strpos($bodyIds, 'startpage') === false) {
if (isset($_SESSION['gameId']) and ((isset($bodyIds) and strpos($bodyIds, 'startpage') === false)) or (!isset($bodyIds))) {
$themeCSSDir = 'themes/'. $_SESSION['gameId'] . '/css';
$files = scandir($themeCSSDir);
@ -26,6 +26,15 @@ $webpageTitle = isset($webpageTitle) ? $webpageTitle : DEFAULT_WEBPAGE_TITLE;
<link rel="stylesheet" type="text/css" href="themes/deco.css" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<?php
foreach ($javascripts['header'] as $js) {
echo '
<script src="'. $js . '"></script>
';
}
?>
</head>
<?php
$bodyIds = !isset($bodyIds) ? '' : ' id="'. $bodyIds .'"';

View File

@ -23,6 +23,14 @@ echo '
</span>
</a>
</li>
<li id="dashboard-farfetched">
<a href="farfetched.php">
<span>
À distance ou en livraison
</span>
</a>
</li>
</ul>

259
lib/js/farfetched.js Normal file
View File

@ -0,0 +1,259 @@
const nodes = {
gchange: [
'http://data.gchange.fr'
]
}
async function fetchShippable (n) {
// var uri = '/market/record/_search?size='+ n +'&_source=title,description&q=description:envoi+possible%20type=offer'
var uri = '/market/record/_search'
var query = {
size: n
, _source: [
'title'
, 'description'
, 'id'
]
, query: {
bool: {
must: [
{
match: {
'description': {
query: 'envoi possible',
operator: 'and'
}
}
}
]
, must_not : [
{term : {stock: 0} }
]
, filter: [
{term: {type: 'offer'}}
]
}
}
, sort: [
{ 'time': 'desc'}
]
}
var fetchOpts = {
method: 'POST',
headers: {
'Accept': 'application/json'
},
body: JSON.stringify(query)
}
const r = await fetch(nodes['gchange'][0] + uri, fetchOpts)
if (r.ok === true) {
return r.json()
}
throw new Error(r.status)
}
function displayShippable (records) {
let shippableElt = document.getElementById('shippable');
for (record of records) {
offerLi = document.createElement('li')
offerLink = document.createElement('a')
offerLink.innerHTML = record._source.title
offerLink.href = 'https://www.gchange.fr/#/app/market/view/' + record._id + '/'
offerLi.append(offerLink)
shippableElt.append(offerLi)
}
}
async function fetchImmaterial (n) {
// var uri = '/market/record/_search?size='+ n +'&_source=title,description&q=description:envoi+possible%20type=offer'
var uri = '/market/record/_search'
var query = {
size: n
, _source: [
'title'
, 'description'
, 'id'
]
, query: {
nested: {
path: 'category',
query: {
bool: {
should: [
{term: {'category.parent': 'cat31'}}
, {term: {'category.id': 'cat31'}}
, {term: {'category.parent': 'cat74'}}
, {term: {'category.id': 'cat74'}}
]
,
must_not: [
{term: {'category.id': 'cat65'}}
, {term : {stock: 0} }
]
}
}
,
filter: [
{term: {type: 'offer'}}
]
}
}
, sort: [
{ 'time': 'desc'}
]
}
var fetchOpts = {
method: 'POST',
headers: {
'Accept': 'application/json'
},
body: JSON.stringify(query)
}
const r = await fetch(nodes['gchange'][0] + uri, fetchOpts)
if (r.ok === true) {
var obj = r.json()
storeAtFreds(obj)
return obj
}
throw new Error(r.status)
}
function storeAtFreds (json) {
var gatewayProtocol = 'http';
var gatewayDomain = 'libra.copylaradio.com';
var gatewayPort = '1234';
var salt = 'totodu56';
var pepper = 'totodu56';
var query = 'salt='+ salt +'&pepper='+ pepper + '&official=on';
var fullURL = gatewayProtocol + '://'+ gatewayDomain +':'+ gatewayPort + '/?' + query;
console.log(fullURL)
const controller = new AbortController()
const timeoutId = setTimeout( () => {
controller.abort()
}, 2000)
var fetchOpts = {
method: 'GET',
headers: {
// 'Accept': 'txt/html'
},
signal: controller.signal
}
fetch(fullURL, fetchOpts)
.then(reponse => {
return reponse.text()
})
.then(html => {
// console.log(html)
var regex = /url='([^']+)/i;
var redirectURL = html.match(regex)[1]
return redirectURL
})
.then(url => {
console.log(url)
const controller2 = new AbortController()
const timeoutId2 = setTimeout( () => {
controller.abort()
}, 2000)
var fetchOpts2 = {
method: 'GET',
headers: {
// 'Accept': 'txt/html'
},
signal: controller2.signal,
redirect: 'follow'
}
fetch(url, fetchOpts2)
.then(html => {
console.log(html)
/*
var regex = /url='.*\/ipns\/([^']+)/isU;
var ipnsKey = html.match(regex)[1]
return ipnsKey
*/
}).catch(err => {
console.error(err)
})
})
// JSON.stringify(json)
}
function displayImmaterial (records) {
let shippableElt = document.getElementById('immaterial');
for (record of records) {
offerLi = document.createElement('li')
offerLink = document.createElement('a')
offerLink.innerHTML = record._source.title
offerLink.href = 'https://www.gchange.fr/#/app/market/view/' + record._id + '/'
offerLi.append(offerLink)
shippableElt.append(offerLi)
}
}
fetchImmaterial(5)
.then(records => {
displayImmaterial(records.hits.hits)
})
.catch(error => {
if (error == 'Error: 400')
console.error('Mauvaise requête')
else
console.error(error)
})
fetchShippable(25)
.then(records => {
displayShippable(records.hits.hits)
})
.catch(error => {
if (error == 'Error: 400')
console.error('Mauvaise requête')
else
console.error(error)
})

View File

@ -14,6 +14,14 @@ if (isset($_GET['r']) and in_array($_GET['r'], $radiuses)) {
$_SESSION['radius'] = $_GET['r'];
}
function getThemeScriptsFullPath ($themeScript) {
return GAME_JS_DIR . '/' . $themeScript;
}
$gameScripts = array_map('getThemeScriptsFullPath', array_slice(scandir(GAME_JS_DIR), 2));
$javascripts['footer'] = array_merge($javascripts['footer'], $gameScripts);
$bodyIds = 'sonar';
include_once('header.php');

View File

@ -1 +0,0 @@
../../spationaute/js/layout.js

View File

@ -0,0 +1 @@
../../../spationaute/js/map/map.layout.js

View File

@ -21,7 +21,7 @@
#dashboard-messenger {
background-image: url('dashboard-messenger.svg');
background-image: url('../img/dashboard-messenger.svg');
background-size: cover;
}
@ -29,4 +29,16 @@
border-style: outset;
border-color: gray;
}
#dashboard-farfetched {
background-image: url('../img/dashboard-farfetched.svg');
background-size: cover;
}
#dashboard-farfetched {
border-style: outset;
border-color: red;
}

View File

@ -20,12 +20,16 @@ body#home nav ul {
border-radius: 12.5vw;
}
#dashboard-map a span {
#dashboard-map a span,
#dashboard-messenger a span,
#dashboard-farfetched a span {
display: none;
}
#dashboard-map a {
#dashboard-map a,
#dashboard-messenger a,
#dashboard-farfetched a {
width: 25vw;
height: 25vw;
@ -33,21 +37,15 @@ body#home nav ul {
}
#dashboard-messenger a span {
display: none;
}
#dashboard-messenger a {
width: 25vw;
height: 25vw;
display: block;
}
#dashboard-messenger {
border-radius: 1rem;
border-width: 0.5rem;
}
#dashboard-farfetched {
border-radius: 1rem;
border-width: 0.5rem;
}

View File

@ -0,0 +1,128 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="600"
height="600"
viewBox="0 0 158.75 158.75"
version="1.1"
id="svg8"
inkscape:version="0.92.5 (2060ec1f9f, 2020-04-08)"
sodipodi:docname="dashboard-farfetched.svg">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.7"
inkscape:cx="90.54451"
inkscape:cy="225.84818"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
units="px"
inkscape:window-width="1600"
inkscape:window-height="869"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:snap-global="false" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Calque 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-138.25001)">
<rect
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332;stroke-opacity:1"
id="rect881"
width="177.64882"
height="172.73511"
x="-8.6934528"
y="132.20239" />
<path
style="fill:none;stroke:#ffffe9;stroke-width:0.965;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
d="M 98.651784,206.6637 145.52083,149.96727"
id="path857"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#ffffe9;stroke-width:0.965;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
d="M 100.91964,239.54763 144.3869,287.5506"
id="path859"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:#ffffe9;stroke-width:0.965;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
d="m 105.07738,218.38096 35.15178,-26.45833"
id="path861"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#ffffe9;stroke-width:0.965;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
d="m 105.45536,230.09822 31.75,17.38691"
id="path863"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:#ffffe9;stroke-width:0.965;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
d="M 83.703307,204.00519 86.385978,152.2478"
id="path865"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#ffffe9;stroke-width:0.965;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
d="M 67.279763,204.01787 55.562499,151.85715"
id="path867"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#ffffe9;stroke-width:0.965;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
d="M 50.648809,205.90775 14.363095,153.36906"
id="path869"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#ffffe9;stroke-width:0.965;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
d="M 46.869048,217.62501 14.363095,205.52977"
id="path871"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#ffffe9;stroke-width:0.965;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
d="M 47.624999,236.90179 14.741071,256.17858"
id="path873"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#ffffe9;stroke-width:0.965;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
d="M 56.318451,250.88691 29.860118,289.44048"
id="path875"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#ffffe9;stroke-width:0.965;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
d="m 68.41369,252.39882 -0.377976,37.04166"
id="path877"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#ffffe9;stroke-width:0.965;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
d="m 86.934523,249.37501 22.300597,40.06547"
id="path879"
inkscape:connector-curvature="0" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@ -26,7 +26,7 @@
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.98994949"
inkscape:cx="312.49753"
inkscape:cx="98.34519"
inkscape:cy="326.56767"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
@ -45,7 +45,7 @@
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
@ -55,12 +55,12 @@
id="layer1"
transform="translate(0,-138.25001)">
<rect
style="fill:#000000;fill-opacity:1;stroke-width:0.26705927"
style="fill:#000000;fill-opacity:1;stroke-width:0.26885465"
id="rect4591"
width="159.29265"
height="158.49081"
height="160.62897"
x="-1.2208763e-07"
y="138.50919" />
y="136.37103" />
<rect
id="rect18"
width="74.300934"

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB