Uso de Websocket en mirar moneda

This commit is contained in:
2021-04-12 00:41:37 -04:00
parent 29d04ac4ad
commit fef167c46e

View File

@ -71,6 +71,18 @@
<label>Url</label>
<input type="text" name="url" />
</div>
<div class="inline field">
<label>Frecuencia</label>
<input type="text" name="frecuency" />
<select name="frec_name" class="ui selection dropdown">
<option value="minute">Minuto(s)</option>
<option value="hour">Hora(s)</option>
<option value="day">D&iacute;a(s)</option>
<option value="week">Semana(s)</option>
<option value="month">Mes(es)</option>
<option value="year">A&ntilde;o(s)</option>
</select>
</div>
<button class="ui button">Agregar</button>
</form>
</div>
@ -84,17 +96,27 @@
add_button: '#add_source',
add_modal: '#add_sources',
loading: '',
loaded: false,
sources: [],
setup: function() {
$(this.id).hide()
$(this.add_button).css('cursor', 'pointer').click((e) => {
this.add()
})
this.buildModal()
},
get: function(currency_id, data) {
this.sources = data.sources
this.populate(currency_id)
socket.sendMessage('currency.values', {currency_id: '{{$currency_id}}'})
if (!this.loaded) {
this.sources = data.sources
this.populate(currency_id)
socket.sendMessage('currency.values', {currency_id: currency_id})
return
}
var url = '{{$urls->api}}/currency/' + currency_id + '/sources'
$.getJSON(url, (data) => {
this.sources = data.sources
this.populate(currency_id)
})
},
buildModal: function() {
$(this.add_modal).modal()
@ -127,14 +149,15 @@
doAdd: function() {
let form = $(this.add_modal).find('form')
let info = {
url: form.find("[name='url']").val()
url: form.find("[name='url']").val(),
frecuency: form.find("[name='frecuency']").val() + ' ' + form.find("[name='frec_name']").val()
}
var url = '{{$urls->api}}/currency/' + this.data.id + '/sources/add'
var url = '{{$urls->api}}/currency/{{$currency_id}}/sources/add'
$(this.add_modal).modal('hide')
$(this.loading).modal('show')
$.post(url, JSON.stringify(info), (data) => {
if (data.sources[0].created) {
this.get()
this.get('{{$currency_id}}')
}
}, 'json').then(() => {
$(this.loading).modal('hide')
@ -163,6 +186,7 @@
add_modal: '#add_values',
loading: '',
values: [],
loaded: false,
setup: function() {
$(this.id).hide()
this.buildModal()
@ -171,12 +195,20 @@
})
},
get: function(currency_id, data) {
if (data.values.length > 0) {
if (!this.loaded) {
if (data.values.length > 0) {
this.values = data.values
this.populate(currency_id)
}
$(this.loading).modal('hide')
socket.conn.close()
return
}
var url = '{{$urls->api}}/currency/' + currency_id + '/values'
$.getJSON(url, (data) => {
this.values = data.values
this.populate(currency_id)
}
$(this.loading).modal('hide')
socket.conn.close()
})
},
buildModal: function() {
this.getCurrencies()
@ -229,12 +261,12 @@
value: form.find("[name='valor']").val(),
base_id: form.find('.ui.dropdown').dropdown('get value')
}
var url = '{{$urls->api}}/currency/' + this.data.id + '/values/add'
var url = '{{$urls->api}}/currency/{{$currency_id}}/values/add'
$(this.add_modal).modal('hide')
$(this.loading).modal('show')
$.post(url, JSON.stringify(info), (data) => {
if (data.values[0].created) {
this.get()
this.get('{{$currency_id}}')
}
}, 'json').then(() => {
$(this.loading).modal('hide')