7 |
7 |
import { ImageSource, fromFile, fromResource, fromBase64, fromAsset } from "tns-core-modules/image-source";
|
8 |
8 |
import { Image } from "tns-core-modules/ui/image";
|
9 |
9 |
import { EventData } from "tns-core-modules/data/observable";
|
10 |
|
import { Button } from "tns-core-modules/ui/button";
|
11 |
10 |
import { getViewById } from "tns-core-modules/ui/core/view";
|
12 |
11 |
import { TextField } from "tns-core-modules/ui/text-field";
|
13 |
|
import * as appversion from "nativescript-appversion";
|
14 |
12 |
import { isAndroid, isIOS, device, screen } from "tns-core-modules/platform";
|
|
13 |
import { ActivityIndicator } from "tns-core-modules/ui/activity-indicator";
|
15 |
14 |
import { getString, setString, hasKey, remove, clear } from "tns-core-modules/application-settings";
|
|
15 |
import { Button } from "tns-core-modules/ui/button";
|
16 |
16 |
|
|
17 |
import * as bghttp from "nativescript-background-http";
|
|
18 |
import * as appversion from "nativescript-appversion";
|
17 |
19 |
import * as dialogs from "tns-core-modules/ui/dialogs";
|
18 |
20 |
import * as app from "tns-core-modules/application";
|
19 |
21 |
import * as imagepicker from "nativescript-imagepicker";
|
... | ... | |
38 |
40 |
public serverName: string;
|
39 |
41 |
public serverURI: string;
|
40 |
42 |
public hasPicture: boolean;
|
|
43 |
public isBusy: boolean = true;
|
41 |
44 |
|
42 |
45 |
|
43 |
46 |
constructor() {
|
... | ... | |
52 |
55 |
else {
|
53 |
56 |
this.appVersion = "Other/" + v;
|
54 |
57 |
}
|
55 |
|
console.log("Your app's version is: " + this.appVersion);
|
|
58 |
console.log("clicalbum: Your app's version is: " + this.appVersion);
|
56 |
59 |
});
|
57 |
60 |
}
|
58 |
61 |
|
... | ... | |
67 |
70 |
this.album = getString("album", "");
|
68 |
71 |
this.albumPass = getString("albumPass", "");
|
69 |
72 |
this.label = "";
|
|
73 |
this.isBusy = false;
|
|
74 |
this.enableButtons("btnSendPicture", false)
|
70 |
75 |
}
|
71 |
76 |
|
|
77 |
enableButtons(btnName, onOff) {
|
|
78 |
let b = <Button>getViewById(app.getRootView(), btnName);
|
|
79 |
if (b) {
|
|
80 |
b.isEnabled = onOff;
|
|
81 |
}
|
|
82 |
}
|
|
83 |
|
|
84 |
|
72 |
85 |
onBlur(args: EventData): void {
|
73 |
86 |
let obj = <TextField>args.object;
|
74 |
87 |
if (obj.id == "album") {
|
... | ... | |
194 |
207 |
}
|
195 |
208 |
|
196 |
209 |
onSendPictureTap(args) {
|
|
210 |
this.enableButtons("btnSendPicture", false)
|
|
211 |
this.isBusy = true;
|
197 |
212 |
let labelObj = <TextField>getViewById(app.getRootView(), "label");
|
198 |
213 |
this.label = labelObj.text;
|
199 |
214 |
let albumObj = <TextField>getViewById(app.getRootView(), "album");
|
200 |
|
this.album = albumObj.text;
|
|
215 |
this.album = albumObj.text.toLowerCase().replace(/[^a-z0-9]/g, "");
|
201 |
216 |
albumObj = <TextField>getViewById(app.getRootView(), "albumPass");
|
202 |
217 |
this.albumPass = albumObj.text;
|
203 |
218 |
|
... | ... | |
210 |
225 |
message: "Il faut renseigner le nom de l'album auquel vous voulez participer et donner un nom à votre photo ...",
|
211 |
226 |
okButtonText: "Ok"
|
212 |
227 |
}).then(() => {
|
|
228 |
this.enableButtons("btnSendPicture", true)
|
|
229 |
this.isBusy = false;
|
|
230 |
console.log("clicalbum: album ou label vide");
|
|
231 |
return;
|
213 |
232 |
});
|
214 |
233 |
}
|
215 |
234 |
else {
|
... | ... | |
220 |
239 |
}
|
221 |
240 |
|
222 |
241 |
sendPicture(args) {
|
|
242 |
this.enableButtons("btnSendPicture", false)
|
|
243 |
this.isBusy = true;
|
223 |
244 |
// let button = args.object as Button;
|
224 |
245 |
const folderPath: string = knownFolders.documents().path;
|
225 |
246 |
const fileName = "fichier_temporaire.jpeg";
|
226 |
247 |
const filePath = path.join(folderPath, fileName);
|
227 |
|
console.log("On voudrait uploader le fichier " + filePath + " dans l'album " + this.album);
|
|
248 |
let labelObj = <TextField>getViewById(app.getRootView(), "label");
|
|
249 |
this.label = labelObj.text;
|
|
250 |
|
|
251 |
console.log("On voudrait uploader le fichier " + filePath + " dans l'album " + this.album + " sous le nom " + this.label);
|
|
252 |
|
|
253 |
if (this.serverURI == "") {
|
|
254 |
dialogs.alert({
|
|
255 |
title: "Serveur ????",
|
|
256 |
message: "Suite à une collision dans l'espace-temps des nano particules permettant la bonne configuration du logiciel l'adresse du serveur s'est retrouvée vide ... bien entendu ce bug ne devrait pas surgir mais pour continuer vous devrez à nouveau choisir un serveur dans la configuration ... Merci pour votre compréhension",
|
|
257 |
okButtonText: "Ok"
|
|
258 |
}).then(() => {
|
|
259 |
this.enableButtons("btnSendPicture", true)
|
|
260 |
this.isBusy = false;
|
|
261 |
console.log("clicalbum: Adresse serveur vide");
|
|
262 |
return;
|
|
263 |
});
|
|
264 |
}
|
228 |
265 |
|
229 |
266 |
var url = "https://" + this.serverURI + "/u.php";
|
|
267 |
console.log("clicalbum: POST vers " + url);
|
230 |
268 |
|
231 |
269 |
// // upload configuration
|
232 |
|
var bghttp = require("nativescript-background-http");
|
233 |
270 |
var session = bghttp.session("image-upload");
|
234 |
271 |
var request = {
|
235 |
272 |
url: url,
|
... | ... | |
252 |
289 |
];
|
253 |
290 |
var task = session.multipartUpload(params, request);
|
254 |
291 |
|
255 |
|
task.on("progress", logEvent);
|
256 |
|
task.on("error", uploadError);
|
257 |
|
task.on("complete", resetPicture);
|
258 |
|
|
|
292 |
task.on("progress", logEvent.bind(this));
|
|
293 |
task.on("error", this.uploadError.bind(this));
|
|
294 |
task.on("complete", this.uploadCompleted.bind(this));
|
259 |
295 |
function logEvent(e) {
|
260 |
|
console.log("UPLOAD STATUS: " + e.eventName);
|
|
296 |
console.log("clicalbum: UPLOAD STATUS: " + e.eventName);
|
261 |
297 |
}
|
|
298 |
}
|
262 |
299 |
|
263 |
|
function uploadError(e) {
|
264 |
|
dialogs.alert({
|
265 |
|
title: "Erreur de transfert",
|
266 |
|
message: "Erreur de transfert, peut-être que cet album est protégé par mot de passe et que celui que vous avez indiqué n'est pas bon ?",
|
267 |
|
okButtonText: "Ok"
|
268 |
|
}).then(() => {
|
|
300 |
uploadError(this) {
|
|
301 |
console.log("clicalbum: UPLOAD ERROR");
|
|
302 |
dialogs.alert({
|
|
303 |
title: "Erreur de téléversement",
|
|
304 |
message: "Pour une raison inconnue le téléversement de votre fichier n'a pas été possible ... si cette erreur persiste merci de nous le signaler via le formulaire de contact disponible sur clicpdf.org",
|
|
305 |
okButtonText: "Ok"
|
|
306 |
}).then(() => {
|
|
307 |
this.enableButtons("btnSendPicture", true)
|
|
308 |
this.isBusy = false;
|
|
309 |
console.log("clicalbum: Dialog closed!");
|
|
310 |
});
|
|
311 |
}
|
269 |
312 |
|
270 |
|
});
|
|
313 |
uploadCompleted(this) {
|
|
314 |
console.log("clicalbum: UPLOAD STATUS: terminé");
|
|
315 |
console.log("clicalbum: UPLOAD STATUS: terminé end");
|
|
316 |
dialogs.alert({
|
|
317 |
title: "Téléversement terminé",
|
|
318 |
message: "Votre document est maintenant sur le serveur",
|
|
319 |
okButtonText: "Ok"
|
|
320 |
}).then(() => {
|
|
321 |
this.isBusy = false;
|
|
322 |
this.displayImage("");
|
|
323 |
this.enableButtons("btnSendPicture", false)
|
|
324 |
console.log("clicalbum: Dialog closed!");
|
|
325 |
});
|
|
326 |
}
|
|
327 |
|
|
328 |
saveImage(image, fileName) {
|
|
329 |
// // =========== sauvegarde de l'image
|
|
330 |
if (image.saveToFile(fileName, "jpeg", 95)) {
|
|
331 |
console.log("clicalbum: Image saved successfully in " + fileName);
|
|
332 |
this.displayImage(fileName);
|
271 |
333 |
}
|
|
334 |
}
|
272 |
335 |
|
273 |
|
function resetPicture() {
|
274 |
|
console.log("UPLOAD STATUS: terminé");
|
275 |
|
this.cameraImage = "res://icon";
|
276 |
|
console.log("UPLOAD STATUS: terminé end");
|
277 |
|
dialogs.alert({
|
278 |
|
title: "Téléversement terminé",
|
279 |
|
message: "Votre document est maintenant sur le serveur",
|
280 |
|
okButtonText: "Ok"
|
281 |
|
}).then(() => {
|
282 |
|
console.log("Dialog closed!");
|
283 |
|
this.cameraImage = "res://icon";
|
284 |
|
});
|
|
336 |
displayImage(fileName) {
|
|
337 |
console.log("clicalbum: displayImage " + fileName);
|
|
338 |
// if (fileName != "") {
|
|
339 |
let i = new ImageSource().fromFile(fileName);
|
|
340 |
this.cameraImage = fileName;
|
|
341 |
// }
|
|
342 |
// let i = <Image>getViewById(app.getRootView(), "cameraImage");
|
|
343 |
// if (i) {
|
|
344 |
// console.log(" objet image ok");
|
|
345 |
|
|
346 |
// if (fileName != "") {
|
|
347 |
// i.src = fileName;
|
|
348 |
// this.enableButtons("btnSendPicture", true)
|
|
349 |
// }
|
|
350 |
// else {
|
|
351 |
// i.src = "res://icon";
|
|
352 |
// }
|
|
353 |
// }
|
|
354 |
|
|
355 |
this.isBusy = false;
|
|
356 |
if (fileName != "") {
|
|
357 |
this.hasPicture = true;
|
|
358 |
}
|
|
359 |
else {
|
|
360 |
this.hasPicture = false;
|
|
361 |
}
|
|
362 |
let b = <ActivityIndicator>getViewById(app.getRootView(), "busyIndicator");
|
|
363 |
if (b) {
|
|
364 |
console.log(" objet busy ok");
|
|
365 |
b.busy = false;
|
285 |
366 |
}
|
|
367 |
|
|
368 |
console.log("clicalbum: end of displayImage");
|
286 |
369 |
}
|
287 |
370 |
|
|
371 |
|
288 |
372 |
imageCropped(image) {
|
289 |
|
this.cameraImage = image;
|
|
373 |
// this.cameraImage = image;
|
290 |
374 |
console.log("imageCropped ...");
|
291 |
375 |
console.log("NEW IMAGE: ", image.height, image.width);
|
292 |
376 |
|
... | ... | |
294 |
378 |
const folderPath: string = knownFolders.documents().path;
|
295 |
379 |
const fileName = "fichier_temporaire.jpeg";
|
296 |
380 |
const filePath = path.join(folderPath, fileName);
|
297 |
|
const saved: boolean = image.saveToFile(filePath, "jpeg", 95);
|
298 |
|
if (saved) {
|
299 |
|
console.log("Image saved successfully in " + filePath);
|
300 |
|
}
|
301 |
|
// // =========== end sauvegarde de l'image
|
302 |
|
this.hasPicture = true;
|
|
381 |
this.saveImage(image, filePath)
|
303 |
382 |
}
|
304 |
383 |
|
305 |
384 |
base64Encode(value) {
|
|
385 |
console.log("clicalbum: base64 pour " + value);
|
306 |
386 |
if (isIOS) {
|
307 |
387 |
let text = NSString.stringWithString(value);
|
308 |
388 |
let data = text.dataUsingEncoding(NSUTF8StringEncoding);
|
... | ... | |
314 |
394 |
}
|
315 |
395 |
}
|
316 |
396 |
|
|
397 |
onBusyChanged(args: EventData) {
|
|
398 |
let indicator: ActivityIndicator = <ActivityIndicator>args.object;
|
|
399 |
console.log("clicalbum: indicator.busy changed to: " + indicator.busy);
|
|
400 |
}
|
|
401 |
|
317 |
402 |
}
|