Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
121 lines (98 loc) · 2.85 KB
/
Copy pathapp.js
File metadata and controls
121 lines (98 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const $ = require('jquery');
const http = require('http');
const ipcRenderer = require('electron').ipcRenderer;
const fs = require('fs');
const appInfo = require('./package.json');
console.log(appInfo.version);
let apiNewsURL = "http://aii-wp-rfig081.c9users.io/api/news_list.json?appVersion="+appInfo.version;
let apiEventURL = "http://aii-wp-rfig081.c9users.io/api/events_list.json?appVersion="+appInfo.version;
let apiAcademico = "";
let data = "";
$('#close-btn').click((e)=>{
e.preventDefault();
ipcRenderer.send('close-btn-click');
});
$('#max-btn').click((e)=>{
e.preventDefault();
ipcRenderer.send('max-btn-click');
});
$('#min-btn').click((e)=>{
e.preventDefault();
ipcRenderer.send('min-btn-click');
});
function displayNews(data)
{
let content = $('#content');
content.empty();
data.forEach(function(noticia) {
content.append('<div class="card"><img class="card-image" src="'+ noticia.image_url +'" /><div class="card-content"><a href="'+noticia.news_url+'" target="_blank"><h5>'+noticia.title+'</h5></a></div></div>');
});
}
function displayEvents(data)
{
let content = $('#content');
content.empty();
data.forEach((evento)=>{
content.append('<div class="card"><img class="card-image" src="'+ evento.image_url +'" /><div class="card-content"><a href="'+evento.event_url+'" target="_blank"><h5>'+evento.title+'</h5></a></div></div>');
});
}
$('#news').click((e)=>{
e.preventDefault();
data = "";
http.get(apiNewsURL, (res) => {
//If server not found
if(res.statusCode == 404){
data = fs.readFile('data/lastNews.json', (err)=>{
if(err){
console.log(err);
}
});
}
//Mientra envie data.
res.on('data', (chunk)=>{
data += chunk;
//console.log(""+chunk);
});
console.log("News Click");
//Cuendo termine el response.
res.on('end', ()=>{
console.log(data);
data = JSON.parse(data);
displayNews(data);
//fs.writeFile('data/lastNews.json',);
});
});
})
$('#events').click((e)=>{
e.preventDefault();
data = "";
console.log("Events Click");
http.get(apiEventURL, (res) => {
//Mientra envie data.
res.on('data', (chunk)=>{
data += chunk;
});
//Cuendo termine el response.
res.once('end', ()=>{
console.log(data);
data = JSON.parse(data);
displayEvents(data);
});
});
})
$('#academic').click((e)=>{
e.preventDefault();
console.log("Academico Click");
http.get(apiAcademico, (res) => {
//Mientra envie data.
res.on('data', (chunk)=>{
data += chunk;
});
//Cuendo termine el response.
res.once('end', ()=>{
console.log(data);
data = JSON.parse(data);
displayAcademic(data);
});
});
})