Commit f0279c46 authored by Nacim Goura's avatar Nacim Goura

modif notif and replace promise by async

parent e92aa55c
......@@ -7,16 +7,16 @@
# base package
meteor-base@1.1.0 # Packages every Meteor app needs to have
mobile-experience@1.0.4 # Packages for a great mobile UX
mongo@1.1.18 # The database Meteor supports right now
mongo@1.1.19-rc.1 # The database Meteor supports right now
blaze-html-templates # Compile .html files into Meteor Blaze views
reactive-var@1.0.11 # Reactive variable for tracker
tracker@1.1.3 # Meteor's client-side reactive programming library
# package for compile and minify
standard-minifier-css@1.3.4 # CSS minifier run for production mode
standard-minifier-js@2.1.0 # JS minifier run for production mode
standard-minifier-js@2.1.1-rc.1 # JS minifier run for production mode
es5-shim@4.6.15 # ECMAScript 5 compatibility for older browsers.
ecmascript@0.8.0 # Enable ECMAScript2015+ syntax in app code
ecmascript@0.8.1 # Enable ECMAScript2015+ syntax in app code
fourseven:scss@4.5.0 # Compile scss to css
fortawesome:fontawesome # pretty icon
......@@ -36,14 +36,14 @@ aldeed:autoform
check@1.2.5
# package for user
accounts-base@1.3.0
accounts-password
accounts-base@1.3.1-rc.1
accounts-password@1.4.0-rc.1
alanning:roles
practicalmeteor:chai
# other packages
deanius:promise
dynamic-import
dynamic-import@0.1.1
aldeed:tabular
ajduke:bootstrap-tagsinput
percolate:synced-cron
......
METEOR@1.5
METEOR@1.5.1-rc.1
accounts-base@1.3.0
accounts-password@1.3.7
accounts-base@1.3.1-rc.1
accounts-password@1.4.0-rc.1
ajduke:bootstrap-tagsinput@0.7.1
alanning:roles@1.2.16
aldeed:autoform@6.2.0
aldeed:collection2-core@2.0.1
aldeed:tabular@2.1.1
allow-deny@1.0.5
allow-deny@1.0.6-rc.1
autoupdate@1.3.12
babel-compiler@6.19.3
babel-runtime@1.0.1
......@@ -22,11 +22,11 @@ check@1.2.5
coffeescript@1.12.6_1
cosmos:browserify@0.10.0
dburles:collection-helpers@1.1.0
ddp@1.2.5
ddp-client@1.3.4
ddp-common@1.2.8
ddp@1.3.0-rc.1
ddp-client@2.0.0-rc.1
ddp-common@1.2.9-rc.1
ddp-rate-limiter@1.0.7
ddp-server@1.3.14
ddp-server@2.0.0-rc.1
deanius:promise@3.1.3
deps@1.0.12
diff-sequence@1.0.7
......@@ -40,7 +40,7 @@ email@1.2.3
es5-shim@4.6.15
fastclick@1.0.13
fortawesome:fontawesome@4.7.0
fourseven:scss@4.5.0
fourseven:scss@4.5.4
geojson-utils@1.0.10
hot-code-push@1.0.4
html-tools@1.0.11
......@@ -56,17 +56,17 @@ livedata@1.0.18
localstorage@1.1.0
logging@1.1.17
matb33:collection-hooks@0.8.4
meteor@1.6.1
meteor@1.7.0-rc.1
meteor-base@1.1.0
minifier-css@1.2.16
minifier-js@2.1.0
minifier-js@2.1.1-rc.1
minimongo@1.2.1
mobile-experience@1.0.4
mobile-status-bar@1.0.14
modules@0.9.2
modules-runtime@0.8.0
momentjs:moment@2.18.1
mongo@1.1.18
mongo@1.1.19-rc.1
mongo-id@1.0.6
npm-bcrypt@0.9.3
npm-mongo@2.2.24
......@@ -94,7 +94,7 @@ spacebars@1.0.15
spacebars-compiler@1.1.2
srp@1.0.10
standard-minifier-css@1.3.4
standard-minifier-js@2.1.0
standard-minifier-js@2.1.1-rc.1
templating@1.3.2
templating-compiler@1.3.2
templating-runtime@1.3.2
......@@ -106,5 +106,5 @@ twbs:bootstrap@3.3.6
ui@1.0.13
underscore@1.0.10
url@1.1.0
webapp@1.3.16
webapp@1.3.17-rc.1
webapp-hashing@1.0.9
import { AutoForm } from 'meteor/aldeed:autoform';
import { displayNotif } from '/imports/api/notif/notif.js';
const hooksFormApiCrawl = {
onSuccess(formType, result) {
Meteor.call('addNotif', {
type: 'info',
title: 'Indexation API : ',
message: `Début de l\'indexation pour ${result.idPage}!`,
save: true,
});
},
onError(formType, error) {
Meteor.call('addNotif', {
type: 'error',
title: 'Indexation API : ',
message: error.reason ? error.reason : error,
save: true,
});
},
onSuccess(formType, result) {},
onError(formType, error) {},
};
AutoForm.hooks({
......
import { AutoForm } from 'meteor/aldeed:autoform';
import { displayNotif } from '/imports/api/notif/notif.js';
import { displayNotif } from '/imports/api/notif/methods';
const hooksFormWebsiteCrawl = {
onSuccess(formType, result) {
......
......@@ -5,28 +5,114 @@ import formApiCrawlSchema from '/imports/api/crawl/api/formApiCrawlSchema';
import IndexGeneric from '/imports/api/indexation/server/indexGeneric';
import IndexWebsite from '/imports/api/indexation/server/indexWebsite';
import IndexApi from '/imports/api/indexation/server/indexApi';
import { addNotif } from '/imports/api/notif/methods';
Meteor.methods({
initIndexElastic() {
this.unblock();
try {
const index = new IndexGeneric();
return index.initElastic();
index.initElastic();
addNotif({
userId: Meteor.userId(),
type: 'info',
title: 'initIndexElastic',
message: 'ElasticSearch à été initialisé correctement!',
save: true,
});
} catch (error) {
addNotif({
userId: Meteor.userId(),
type: 'error',
title: 'initIndexElastic',
message: error,
save: true,
});
}
},
reIndexElastic() {
this.unblock();
try {
const index = new IndexGeneric();
return index.reIndex();
index.reIndex();
addNotif({
userId: Meteor.userId(),
type: 'info',
title: 'reIndexElastic',
message: 'ElasticSearch à été réindexé correctement!',
save: true,
});
} catch (error) {
addNotif({
userId: Meteor.userId(),
type: 'error',
title: 'reIndexElastic',
message: error,
save: true,
});
}
},
indexWebsite(url) {
check(url, String);
addNotif({
userId: Meteor.userId(),
type: 'info',
title: 'indexWebsite',
message: `Début de l'indexation pour ${url}!`,
save: true,
});
try {
const index = new IndexWebsite();
return index.indexationWebsite(url);
index.indexationWebsite(url)
.then((result) => {
addNotif({
userId: Meteor.userId(),
type: 'info',
title: 'indexWebsite',
message: result.message,
save: true,
});
});
} catch (error) {
addNotif({
userId: Meteor.userId(),
type: 'error',
title: 'indexWebsite',
message: error,
save: true,
});
}
},
indexApi(data) {
check(data, Object);
formApiCrawlSchema.validate(data);
addNotif({
userId: Meteor.userId(),
type: 'info',
title: 'indexApi',
message: `Début de l'indexation ${data.type} pour ${data.idPage}!`,
save: true,
});
try {
const index = new IndexApi();
index.indexationApi(data);
return data;
index.indexationApi(data)
.then((result) => {
addNotif({
userId: Meteor.userId(),
type: 'info',
title: 'indexApi',
message: result.message,
save: true,
});
});
} catch (error) {
addNotif({
userId: Meteor.userId(),
type: 'error',
title: 'indexApi',
message: error,
save: true,
});
}
},
});
......@@ -9,14 +9,16 @@ export default class IndexApi extends IndexGeneric {
* @param data
* @returns Promise
*/
indexationApi(data) {
async indexationApi(data) {
try {
const crawlApi = new CrawlApi();
crawlApi.init(data)
.then((dataToIndex) => {
this.indexByBulk(dataToIndex)
.then(result => this.notifyUser(result));
}).catch((error) => {
throw error;
});
const dataToIndex = await crawlApi.init(data);
const resultIndex = await this.indexByBulk(dataToIndex);
return {
message: `Indexation ${data.type} de ${resultIndex.items.length} liens pour ${data.idPage} fini avec succès!`,
};
} catch (error) {
throw new Meteor.Error(error);
}
}
}
......@@ -30,17 +30,9 @@ export default class IndexGeneric {
*/
initElastic() {
const analyser = configElastic.analyser;
const mapping = configElastic.mapping;
return indexationElastic.initAnalyzer(esIndex, analyser)
.then(() => indexationElastic.initMapping(esIndex, esType, mapping));
}
/**
* Add element on collection to warn the user of the end
*/
notifyUser(result) {
addNotif(result);
}
}
......@@ -10,15 +10,14 @@ export default class IndexWebsite extends IndexGeneric {
* @returns Promise
*/
async indexationWebsite(urlWebsite) {
return new CrawlWebsite(urlWebsite)
.then(dataToIndex => new Promise(async resolve => resolve({
index: await this.indexByBulk(dataToIndex),
dataForm: {
urlWebsite,
},
})))
.catch((error) => {
throw error;
});
try {
const dataToIndex = await new CrawlWebsite(urlWebsite);
const resultIndex = await this.indexByBulk(dataToIndex);
return {
message: `Indexation de ${resultIndex.items.length} liens pour ${urlWebsite} fini avec succès!`,
};
} catch (error) {
throw new Meteor.Error(error);
}
}
}
......@@ -3,7 +3,7 @@ import { AutoForm } from 'meteor/aldeed:autoform';
import { Meteor } from 'meteor/meteor';
import { Session } from 'meteor/session';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { displayNotif } from '/imports/api/notif/notif.js';
import { displayNotif } from '/imports/api/notif/methods';
const hooksFormLogin = {
onSubmit: (insertDoc, updateDoc, currentDoc) => {
......
......@@ -2,11 +2,36 @@
import { Meteor } from 'meteor/meteor';
import notifsCollection from '/imports/api/notif/notifsCollection';
/**
* display notif for user
* @param options
*/
export function displayNotif(options) {
this.options = {
position: 'topCenter',
};
if (!options.timeout && options.type === 'error') {
this.options.timeout = 10000;
}
Object.assign(this.options, options);
if (Meteor.isClient) {
import('izitoast').then((iziToast) => {
iziToast[this.options.type](this.options);
});
}
}
export function addNotif(notif) {
notif.userId = this.userId;
notif.userId = notif.userId || this.userId;
notifsCollection.insert(notif);
}
Meteor.methods({
addNotif,
displayNotif,
});
import { Meteor } from 'meteor/meteor';
import iziToast from 'izitoast';
/**
* display notif for user
* @param options
*/
export function displayNotif(options) {
this.options = {
position: 'topCenter',
};
if (!options.timeout && options.type === 'error') {
this.options.timeout = 10000;
}
Object.assign(this.options, options);
iziToast[this.options.type](this.options);
}
import SimpleSchema from 'simpl-schema';
import { Mongo } from 'meteor/mongo';
import moment from 'moment';
/**
* this collection keep tracks of all notification of this application
......@@ -21,7 +22,7 @@ SimpleSchema.notifsCollection = new SimpleSchema({
},
createdAt: {
type: Date,
defaultValue: new Date(),
defaultValue: moment().toDate(),
},
userId: {
type: String,
......
......@@ -3,14 +3,10 @@ import { Meteor } from 'meteor/meteor';
import moment from 'moment';
import notifsCollection from '/imports/api/notif/notifsCollection';
console.log(moment().subtract(5, 'm').toISOString(), moment().add(5, 'm').toISOString());
Meteor.publish('notif', function () {
return notifsCollection.find({
userId: this.userId,
Meteor.publish('notif', () => notifsCollection.find({
userId: Meteor.userId(),
createdAt: {
$gte: moment().subtract(5, 'm').toISOString(),
$lt: moment().add(5, 'm').toISOString(),
$gte: moment().subtract(15, 's').toDate(),
$lt: moment().add(15, 's').toDate(),
},
});
});
}));
import SimpleSchema from 'simpl-schema';
import { Mongo } from 'meteor/mongo';
import moment from 'moment';
/**
* this local collection keep tracks of all tabs of this application
......@@ -37,7 +38,7 @@ SimpleSchema.TabsCollection = new SimpleSchema({
},
createdAt: {
type: Date,
defaultValue: new Date(),
defaultValue: moment().toDate(),
},
});
......
import SimpleSchema from 'simpl-schema';
import { Mongo } from 'meteor/mongo';
import moment from 'moment';
/**
* this collection is temporaire for testsearch
......@@ -25,7 +26,7 @@ SimpleSchema.testSearchCollection = new SimpleSchema({
},
createdAt: {
type: Date,
defaultValue: new Date(),
defaultValue: moment().toDate(),
},
});
......
......@@ -2,7 +2,7 @@
import { Meteor } from 'meteor/meteor';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { BlazeLayout } from 'meteor/kadira:blaze-layout';
import displayNotif from '/imports/api/notif/notif';
import { displayNotif } from '/imports/api/notif/methods';
// Import layout templates
import '/imports/ui/layouts/main/main';
......
......@@ -4,7 +4,7 @@ import { Template } from 'meteor/templating';
import { Session } from 'meteor/session';
import formSearchSchema from '/imports/api/search/formSearchSchema';
import '/imports/api/search/formSearchHooks';
import displayNotif from '/imports/api/notif/notif';
import { displayNotif } from '/imports/api/notif/methods';
import '/imports/ui/components/resultSearch/resultSearch';
......
......@@ -2,7 +2,7 @@
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import notifsCollection from '/imports/api/notif/notifsCollection';
import { displayNotif } from '/imports/api/notif/notif';
import { displayNotif } from '/imports/api/notif/methods';
import './sidebar.html';
......@@ -14,7 +14,7 @@ Template.sidebarLayoutTpl.onCreated(() => {
const query = notifsCollection.find({});
query.observeChanges({
added(item, id, fields) {
// console.log(id);
console.log(id);
displayNotif(id);
},
});
......
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import displayNotif from '/imports/api/notif/notif';
import { displayNotif } from '/imports/api/notif/methods';
import './add.html';
......
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import { displayNotif } from '/imports/api/notif/methods';
import displayNotif from '/imports/api/notif/notif';
import '/imports/tabular/configClient';
import './list.html';
......
......@@ -8,6 +8,7 @@ import '../../../components/tabs/tabs';
import './main/main';
import './site/site';
import './api/api';
import './reseau/reseau';
import './indexation.html';
......
......@@ -2,7 +2,7 @@
import { Template } from 'meteor/templating';
import { Meteor } from 'meteor/meteor';
import swal from 'sweetalert2';
import { displayNotif } from '/imports/api/notif/notif.js';
import { displayNotif } from '/imports/api/notif/methods';
import './main.html';
......@@ -18,40 +18,11 @@ Template.mainIndexationTpl.events({
confirmButtonText: 'Oui!',
cancelButtonText: 'Non!',
}).then(() => {
Meteor.callPromise('initIndexElastic')
.then(() => {
Meteor.call('addNotif', {
type: 'success',
title: 'Indexation : ',
message: 'ElasticSearch à été initialisé correctement!',
save: true,
});
}).catch((error) => {
Meteor.call('addNotif', {
type: 'error',
title: 'Indexation : ',
message: error.reason ? error.reason : error,
save: true,
});
});
Meteor.callPromise('initIndexElastic');
});
},
'click #reindexElastic': (event) => {
event.preventDefault();
Meteor.callPromise('reIndexElastic')
.then(() => {
displayNotif({
type: 'success',
title: 'Indexation : ',
message: 'ElasticSearch à été réindexé correctement!',
});
}).catch((error) => {
displayNotif({
type: 'error',
title: 'Indexation : ',
message: error.reason ? error.reason : error,
});
});
Meteor.callPromise('reIndexElastic');
},
});
<template name="reseauIndexationTpl">
<!-- template reseauIndexationTpl -->
<div class="panel panel-default wrapper">
<div class="panel-body">
<h4 class="text-center">Gestion de l'indexation des réseaux</h4>
</div>
</div>
</template>
......@@ -2,7 +2,7 @@
import { Template } from 'meteor/templating';
import { Meteor } from 'meteor/meteor';
import $ from 'jquery';
import { displayNotif } from '/imports/api/notif/notif.js';
import { displayNotif } from '/imports/api/notif/methods';
import formWebsiteCrawlSchema from '/imports/api/crawl/website/formWebsiteCrawlSchema';
import '/imports/api/crawl/website/formWebsiteCrawlHooks';
......@@ -37,27 +37,7 @@ Template.siteIndexationTpl.events({
const url = event.target.urlSite.value;
$(event.target).find('h4').removeClass('hidden');
Meteor.callPromise('indexWebsite', url)
.then((result) => {
$(event.target).find('h4').addClass('hidden');
displayNotif({
type: 'success',
title: 'Indexation : ',
message: `Indexation de ${url} fini avec succès avec ${result.index.items.length} pages indexées!`,
save: true,
});
}).catch((error) => {
$(event.target).find('h4').addClass('hidden');
console.log(error);
displayNotif({
type: 'error',
title: 'Indexation : ',
message: error.reason ? error.reason : error,
save: true,
});
});
Meteor.callPromise('indexWebsite', url);
},
'submit #formReglageSite': (event) => {
event.preventDefault();
......
......@@ -35,6 +35,15 @@
"activ": false,
"closable": false,
"sort": 3
},
{
"module": "indexation",
"layout": "reseauIndexationTpl",
"label": "index Réseau",
"state": {},
"activ": false,
"closable": false,
"sort": 4
}
],
"account": [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment