-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement 'sync' web UI button for remote questions sync execution.
- Loading branch information
Showing
6 changed files
with
137 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
body { | ||
padding: 50px; | ||
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; | ||
} | ||
|
||
a { | ||
color: #00B7FF; | ||
} | ||
|
||
.button { | ||
margin: auto; | ||
background: #00B7FF; | ||
border-radius: 3px; | ||
bottom: 70px; | ||
box-shadow: 2px 7px 7px 0 rgba(0, 0, 0, .2); | ||
color: rgb(48, 40, 42); | ||
display: block; | ||
font-weight: bold; | ||
height: 70px; | ||
line-height: 70px; | ||
text-align: center; | ||
text-decoration: none; | ||
text-transform: uppercase; | ||
width: 250px; | ||
font-size: medium; | ||
} | ||
|
||
.button:hover { | ||
background: rgb(48, 40, 42); | ||
color: #00dfff; | ||
cursor: pointer; | ||
} | ||
|
||
.button.loading { | ||
background: gainsboro; | ||
cursor: wait; | ||
} | ||
|
||
.button.loading:hover { | ||
color: #353535; | ||
} | ||
|
||
#info { | ||
height: 50px; | ||
line-height: 50px; | ||
margin-top: 10px; | ||
} | ||
|
||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* eslint-env jquery */ | ||
const apiUrl = document.location.href // 'https://jusimil-meli-manager.now.sh' | ||
|
||
const dateDaysAgo = (days = 7) => new Date(Date.now() - (1000 * 60 * 60 * 24 * days)) | ||
|
||
const toDDMMYY = date => `${String(date.getDate()).padStart(2, '0')}-${String(date.getMonth()).padStart(2, '0')}-${date.getFullYear() % 1000}` | ||
|
||
const state = { | ||
loading: false | ||
} | ||
|
||
const _onLoad = () => $('#sincronizar').on('click', () => { | ||
if (state.loading) { | ||
console.log('already loading! please wait') | ||
return | ||
} | ||
state.loading = true | ||
|
||
const dots = 5 | ||
const start = 0 | ||
const intervalMs = 1000 | ||
let i = 3 | ||
const loadingInterval = setInterval(() => { | ||
i = i > dots ? start : ++i | ||
$('#info').html(`<p>Cargando${'.'.repeat(i)}</p>`) | ||
}, intervalMs) | ||
const $actionButton = $('#sincronizar') | ||
$actionButton.prop('disabled', 'disabled') | ||
$actionButton.addClass('loading') | ||
|
||
const _onDone = () => { | ||
console.log('done') | ||
clearInterval(loadingInterval) | ||
|
||
$actionButton.removeClass('loading') | ||
$actionButton.prop('disabled', false) | ||
state.loading = false | ||
} | ||
|
||
const settings = { | ||
async: true, | ||
crossDomain: true, | ||
url: `${apiUrl}question?start=${toDDMMYY(dateDaysAgo(7))}&store=true`, | ||
method: 'GET', | ||
headers: { | ||
'Cache-Control': 'no-cache', | ||
Host: apiUrl, | ||
'Accept-Encoding': 'gzip, deflate', | ||
Connection: 'keep-alive' | ||
}, | ||
success: data => { | ||
_onDone() | ||
$('#info').html('<p>¡Sincronización exitosa!</p>') | ||
console.log('success', data) | ||
}, | ||
error: error => { | ||
_onDone() | ||
$('#info').html('<p>Ocurrio un error :(</p>') | ||
console.error('error: ', error) | ||
} | ||
} | ||
|
||
$.ajax(settings) | ||
}) | ||
|
||
$(document).ready(() => { | ||
console.log('Ready!') | ||
_onLoad() | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
<h1>{{title}}</h1> | ||
<p>Welcome to {{title}}</p> | ||
<div class="container"> | ||
<a class="button" id="sincronizar">Sincronización Manual</a> | ||
<div id="info"></div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<head> | ||
<title>{{title}}</title> | ||
<link rel='stylesheet' href='/stylesheets/style.css' /> | ||
</head> | ||
<body> | ||
{{{body}}} | ||
</body> | ||
<link rel='stylesheet' href='/public/css/style.css'/> | ||
<script src='https://code.jquery.com/jquery-3.4.1.min.js'></script> | ||
<script src="/public/js/index.js"></script> | ||
<title>MeLi Manager</title> | ||
</head> | ||
<body> | ||
{{{body}}} | ||
</body> | ||
</html> |