Uso de Websocket en mirar moneda
This commit is contained in:
@ -71,6 +71,18 @@
|
|||||||
<label>Url</label>
|
<label>Url</label>
|
||||||
<input type="text" name="url" />
|
<input type="text" name="url" />
|
||||||
</div>
|
</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ía(s)</option>
|
||||||
|
<option value="week">Semana(s)</option>
|
||||||
|
<option value="month">Mes(es)</option>
|
||||||
|
<option value="year">Año(s)</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<button class="ui button">Agregar</button>
|
<button class="ui button">Agregar</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
@ -84,17 +96,27 @@
|
|||||||
add_button: '#add_source',
|
add_button: '#add_source',
|
||||||
add_modal: '#add_sources',
|
add_modal: '#add_sources',
|
||||||
loading: '',
|
loading: '',
|
||||||
|
loaded: false,
|
||||||
sources: [],
|
sources: [],
|
||||||
setup: function() {
|
setup: function() {
|
||||||
$(this.id).hide()
|
$(this.id).hide()
|
||||||
$(this.add_button).css('cursor', 'pointer').click((e) => {
|
$(this.add_button).css('cursor', 'pointer').click((e) => {
|
||||||
this.add()
|
this.add()
|
||||||
})
|
})
|
||||||
|
this.buildModal()
|
||||||
},
|
},
|
||||||
get: function(currency_id, data) {
|
get: function(currency_id, data) {
|
||||||
this.sources = data.sources
|
if (!this.loaded) {
|
||||||
this.populate(currency_id)
|
this.sources = data.sources
|
||||||
socket.sendMessage('currency.values', {currency_id: '{{$currency_id}}'})
|
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() {
|
buildModal: function() {
|
||||||
$(this.add_modal).modal()
|
$(this.add_modal).modal()
|
||||||
@ -127,14 +149,15 @@
|
|||||||
doAdd: function() {
|
doAdd: function() {
|
||||||
let form = $(this.add_modal).find('form')
|
let form = $(this.add_modal).find('form')
|
||||||
let info = {
|
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.add_modal).modal('hide')
|
||||||
$(this.loading).modal('show')
|
$(this.loading).modal('show')
|
||||||
$.post(url, JSON.stringify(info), (data) => {
|
$.post(url, JSON.stringify(info), (data) => {
|
||||||
if (data.sources[0].created) {
|
if (data.sources[0].created) {
|
||||||
this.get()
|
this.get('{{$currency_id}}')
|
||||||
}
|
}
|
||||||
}, 'json').then(() => {
|
}, 'json').then(() => {
|
||||||
$(this.loading).modal('hide')
|
$(this.loading).modal('hide')
|
||||||
@ -163,6 +186,7 @@
|
|||||||
add_modal: '#add_values',
|
add_modal: '#add_values',
|
||||||
loading: '',
|
loading: '',
|
||||||
values: [],
|
values: [],
|
||||||
|
loaded: false,
|
||||||
setup: function() {
|
setup: function() {
|
||||||
$(this.id).hide()
|
$(this.id).hide()
|
||||||
this.buildModal()
|
this.buildModal()
|
||||||
@ -171,12 +195,20 @@
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
get: function(currency_id, data) {
|
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.values = data.values
|
||||||
this.populate(currency_id)
|
this.populate(currency_id)
|
||||||
}
|
})
|
||||||
$(this.loading).modal('hide')
|
|
||||||
socket.conn.close()
|
|
||||||
},
|
},
|
||||||
buildModal: function() {
|
buildModal: function() {
|
||||||
this.getCurrencies()
|
this.getCurrencies()
|
||||||
@ -229,12 +261,12 @@
|
|||||||
value: form.find("[name='valor']").val(),
|
value: form.find("[name='valor']").val(),
|
||||||
base_id: form.find('.ui.dropdown').dropdown('get value')
|
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.add_modal).modal('hide')
|
||||||
$(this.loading).modal('show')
|
$(this.loading).modal('show')
|
||||||
$.post(url, JSON.stringify(info), (data) => {
|
$.post(url, JSON.stringify(info), (data) => {
|
||||||
if (data.values[0].created) {
|
if (data.values[0].created) {
|
||||||
this.get()
|
this.get('{{$currency_id}}')
|
||||||
}
|
}
|
||||||
}, 'json').then(() => {
|
}, 'json').then(() => {
|
||||||
$(this.loading).modal('hide')
|
$(this.loading).modal('hide')
|
||||||
|
Reference in New Issue
Block a user