Commit f0279c46 authored by Nacim Goura's avatar Nacim Goura

modif notif and replace promise by async

parent e92aa55c
...@@ -7,16 +7,16 @@ ...@@ -7,16 +7,16 @@
# base package # base package
meteor-base@1.1.0 # Packages every Meteor app needs to have meteor-base@1.1.0 # Packages every Meteor app needs to have
mobile-experience@1.0.4 # Packages for a great mobile UX 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 blaze-html-templates # Compile .html files into Meteor Blaze views
reactive-var@1.0.11 # Reactive variable for tracker reactive-var@1.0.11 # Reactive variable for tracker
tracker@1.1.3 # Meteor's client-side reactive programming library tracker@1.1.3 # Meteor's client-side reactive programming library
# package for compile and minify # package for compile and minify
standard-minifier-css@1.3.4 # CSS minifier run for production mode 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. 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 fourseven:scss@4.5.0 # Compile scss to css
fortawesome:fontawesome # pretty icon fortawesome:fontawesome # pretty icon
...@@ -36,14 +36,14 @@ aldeed:autoform ...@@ -36,14 +36,14 @@ aldeed:autoform
check@1.2.5 check@1.2.5
# package for user # package for user
accounts-base@1.3.0 accounts-base@1.3.1-rc.1
accounts-password accounts-password@1.4.0-rc.1
alanning:roles alanning:roles
practicalmeteor:chai practicalmeteor:chai
# other packages # other packages
deanius:promise deanius:promise
dynamic-import dynamic-import@0.1.1
aldeed:tabular aldeed:tabular
ajduke:bootstrap-tagsinput ajduke:bootstrap-tagsinput
percolate:synced-cron percolate:synced-cron
......
METEOR@1.5 METEOR@1.5.1-rc.1
accounts-base@1.3.0 accounts-base@1.3.1-rc.1
accounts-password@1.3.7 accounts-password@1.4.0-rc.1
ajduke:bootstrap-tagsinput@0.7.1 ajduke:bootstrap-tagsinput@0.7.1
alanning:roles@1.2.16 alanning:roles@1.2.16
aldeed:autoform@6.2.0 aldeed:autoform@6.2.0
aldeed:collection2-core@2.0.1 aldeed:collection2-core@2.0.1
aldeed:tabular@2.1.1 aldeed:tabular@2.1.1
allow-deny@1.0.5 allow-deny@1.0.6-rc.1
autoupdate@1.3.12 autoupdate@1.3.12
babel-compiler@6.19.3 babel-compiler@6.19.3
babel-runtime@1.0.1 babel-runtime@1.0.1
...@@ -22,11 +22,11 @@ check@1.2.5 ...@@ -22,11 +22,11 @@ check@1.2.5
coffeescript@1.12.6_1 coffeescript@1.12.6_1
cosmos:browserify@0.10.0 cosmos:browserify@0.10.0
dburles:collection-helpers@1.1.0 dburles:collection-helpers@1.1.0
ddp@1.2.5 ddp@1.3.0-rc.1
ddp-client@1.3.4 ddp-client@2.0.0-rc.1
ddp-common@1.2.8 ddp-common@1.2.9-rc.1
ddp-rate-limiter@1.0.7 ddp-rate-limiter@1.0.7
ddp-server@1.3.14 ddp-server@2.0.0-rc.1
deanius:promise@3.1.3 deanius:promise@3.1.3
deps@1.0.12 deps@1.0.12
diff-sequence@1.0.7 diff-sequence@1.0.7
...@@ -40,7 +40,7 @@ email@1.2.3 ...@@ -40,7 +40,7 @@ email@1.2.3
es5-shim@4.6.15 es5-shim@4.6.15
fastclick@1.0.13 fastclick@1.0.13
fortawesome:fontawesome@4.7.0 fortawesome:fontawesome@4.7.0
fourseven:scss@4.5.0 fourseven:scss@4.5.4
geojson-utils@1.0.10 geojson-utils@1.0.10
hot-code-push@1.0.4 hot-code-push@1.0.4
html-tools@1.0.11 html-tools@1.0.11
...@@ -56,17 +56,17 @@ livedata@1.0.18 ...@@ -56,17 +56,17 @@ livedata@1.0.18
localstorage@1.1.0 localstorage@1.1.0
logging@1.1.17 logging@1.1.17
matb33:collection-hooks@0.8.4 matb33:collection-hooks@0.8.4
meteor@1.6.1 meteor@1.7.0-rc.1
meteor-base@1.1.0 meteor-base@1.1.0
minifier-css@1.2.16 minifier-css@1.2.16
minifier-js@2.1.0 minifier-js@2.1.1-rc.1
minimongo@1.2.1 minimongo@1.2.1
mobile-experience@1.0.4 mobile-experience@1.0.4
mobile-status-bar@1.0.14 mobile-status-bar@1.0.14
modules@0.9.2 modules@0.9.2
modules-runtime@0.8.0 modules-runtime@0.8.0
momentjs:moment@2.18.1 momentjs:moment@2.18.1
mongo@1.1.18 mongo@1.1.19-rc.1
mongo-id@1.0.6 mongo-id@1.0.6
npm-bcrypt@0.9.3 npm-bcrypt@0.9.3
npm-mongo@2.2.24 npm-mongo@2.2.24
...@@ -94,7 +94,7 @@ spacebars@1.0.15 ...@@ -94,7 +94,7 @@ spacebars@1.0.15
spacebars-compiler@1.1.2 spacebars-compiler@1.1.2
srp@1.0.10 srp@1.0.10
standard-minifier-css@1.3.4 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@1.3.2
templating-compiler@1.3.2 templating-compiler@1.3.2
templating-runtime@1.3.2 templating-runtime@1.3.2
...@@ -106,5 +106,5 @@ twbs:bootstrap@3.3.6 ...@@ -106,5 +106,5 @@ twbs:bootstrap@3.3.6
ui@1.0.13 ui@1.0.13
underscore@1.0.10 underscore@1.0.10
url@1.1.0 url@1.1.0
webapp@1.3.16 webapp@1.3.17-rc.1
webapp-hashing@1.0.9 webapp-hashing@1.0.9
import { AutoForm } from 'meteor/aldeed:autoform'; import { AutoForm } from 'meteor/aldeed:autoform';
import { displayNotif } from '/imports/api/notif/notif.js';
const hooksFormApiCrawl = { const hooksFormApiCrawl = {
onSuccess(formType, result) { onSuccess(formType, result) {},
Meteor.call('addNotif', { onError(formType, error) {},
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,
});
},
}; };
AutoForm.hooks({ AutoForm.hooks({
......
import { AutoForm } from 'meteor/aldeed:autoform'; import { AutoForm } from 'meteor/aldeed:autoform';
import { displayNotif } from '/imports/api/notif/notif.js'; import { displayNotif } from '/imports/api/notif/methods';
const hooksFormWebsiteCrawl = { const hooksFormWebsiteCrawl = {
onSuccess(formType, result) { onSuccess(formType, result) {
......
...@@ -5,28 +5,114 @@ import formApiCrawlSchema from '/imports/api/crawl/api/formApiCrawlSchema'; ...@@ -5,28 +5,114 @@ import formApiCrawlSchema from '/imports/api/crawl/api/formApiCrawlSchema';
import IndexGeneric from '/imports/api/indexation/server/indexGeneric'; import IndexGeneric from '/imports/api/indexation/server/indexGeneric';
import IndexWebsite from '/imports/api/indexation/server/indexWebsite'; import IndexWebsite from '/imports/api/indexation/server/indexWebsite';
import IndexApi from '/imports/api/indexation/server/indexApi'; import IndexApi from '/imports/api/indexation/server/indexApi';
import { addNotif } from '/imports/api/notif/methods';
Meteor.methods({ Meteor.methods({
initIndexElastic() { initIndexElastic() {
this.unblock(); this.unblock();
const index = new IndexGeneric(); try {
return index.initElastic(); const index = new IndexGeneric();
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() { reIndexElastic() {
this.unblock(); this.unblock();
const index = new IndexGeneric(); try {
return index.reIndex(); const index = new IndexGeneric();
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) { indexWebsite(url) {
check(url, String); check(url, String);
const index = new IndexWebsite(); addNotif({
return index.indexationWebsite(url); userId: Meteor.userId(),
type: 'info',
title: 'indexWebsite',
message: `Début de l'indexation pour ${url}!`,
save: true,
});
try {
const index = new IndexWebsite();
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) { indexApi(data) {
check(data, Object); check(data, Object);
formApiCrawlSchema.validate(data); formApiCrawlSchema.validate(data);
const index = new IndexApi(); addNotif({
index.indexationApi(data); userId: Meteor.userId(),
return data; 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)
.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 { ...@@ -9,14 +9,16 @@ export default class IndexApi extends IndexGeneric {
* @param data * @param data
* @returns Promise * @returns Promise
*/ */
indexationApi(data) { async indexationApi(data) {
const crawlApi = new CrawlApi(); try {
crawlApi.init(data) const crawlApi = new CrawlApi();
.then((dataToIndex) => { const dataToIndex = await crawlApi.init(data);
this.indexByBulk(dataToIndex) const resultIndex = await this.indexByBulk(dataToIndex);
.then(result => this.notifyUser(result)); return {
}).catch((error) => { message: `Indexation ${data.type} de ${resultIndex.items.length} liens pour ${data.idPage} fini avec succès!`,
throw error; };
}); } catch (error) {
throw new Meteor.Error(error);
}
} }
} }
...@@ -30,17 +30,9 @@ export default class IndexGeneric { ...@@ -30,17 +30,9 @@ export default class IndexGeneric {
*/ */
initElastic() { initElastic() {
const analyser = configElastic.analyser; const analyser = configElastic.analyser;
const mapping = configElastic.mapping; const mapping = configElastic.mapping;
return indexationElastic.initAnalyzer(esIndex, analyser) return indexationElastic.initAnalyzer(esIndex, analyser)
.then(() => indexationElastic.initMapping(esIndex, esType, mapping)); .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 { ...@@ -10,15 +10,14 @@ export default class IndexWebsite extends IndexGeneric {
* @returns Promise * @returns Promise
*/ */
async indexationWebsite(urlWebsite) { async indexationWebsite(urlWebsite) {
return new CrawlWebsite(urlWebsite) try {
.then(dataToIndex => new Promise(async resolve => resolve({ const dataToIndex = await new CrawlWebsite(urlWebsite);
index: await this.indexByBulk(dataToIndex), const resultIndex = await this.indexByBulk(dataToIndex);
dataForm: { return {
urlWebsite, message: `Indexation de ${resultIndex.items.length} liens pour ${urlWebsite} fini avec succès!`,
}, };
}))) } catch (error) {
.catch((error) => { throw new Meteor.Error(error);
throw error; }
});
} }
} }
...@@ -3,7 +3,7 @@ import { AutoForm } from 'meteor/aldeed:autoform'; ...@@ -3,7 +3,7 @@ import { AutoForm } from 'meteor/aldeed:autoform';
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { Session } from 'meteor/session'; import { Session } from 'meteor/session';
import { FlowRouter } from 'meteor/kadira:flow-router'; import { FlowRouter } from 'meteor/kadira:flow-router';
import { displayNotif } from '/imports/api/notif/notif.js'; import { displayNotif } from '/imports/api/notif/methods';
const hooksFormLogin = { const hooksFormLogin = {
onSubmit: (insertDoc, updateDoc, currentDoc) => { onSubmit: (insertDoc, updateDoc, currentDoc) => {
......
...@@ -2,11 +2,36 @@ ...@@ -2,11 +2,36 @@
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import notifsCollection from '/imports/api/notif/notifsCollection'; 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) { export function addNotif(notif) {
notif.userId = this.userId; notif.userId = notif.userId || this.userId;
notifsCollection.insert(notif); notifsCollection.insert(notif);
} }
Meteor.methods({ Meteor.methods({
addNotif, 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 SimpleSchema from 'simpl-schema';
import { Mongo } from 'meteor/mongo'; import { Mongo } from 'meteor/mongo';
import moment from 'moment';
/** /**
* this collection keep tracks of all notification of this application * this collection keep tracks of all notification of this application
...@@ -21,7 +22,7 @@ SimpleSchema.notifsCollection = new SimpleSchema({ ...@@ -21,7 +22,7 @@ SimpleSchema.notifsCollection = new SimpleSchema({
}, },
createdAt: { createdAt: {
type: Date, type: Date,
defaultValue: new Date(), defaultValue: moment().toDate(),
}, },
userId: { userId: {
type: String, type: String,
......
...@@ -3,14 +3,10 @@ import { Meteor } from 'meteor/meteor'; ...@@ -3,14 +3,10 @@ import { Meteor } from 'meteor/meteor';
import moment from 'moment'; import moment from 'moment';
import notifsCollection from '/imports/api/notif/notifsCollection'; import notifsCollection from '/imports/api/notif/notifsCollection';
console.log(moment().subtract(5, 'm').toISOString(), moment().add(5, 'm').toISOString()); Meteor.publish('notif', () => notifsCollection.find({
userId: Meteor.userId(),
Meteor.publish('notif', function () { createdAt: {
return notifsCollection.find({ $gte: moment().subtract(15, 's').toDate(),
userId: this.userId, $lt: moment().add(15, 's').toDate(),
createdAt: { },
$gte: moment().subtract(5, 'm').toISOString(), }));
$lt: moment().add(5, 'm').toISOString(),
},
});
});
import SimpleSchema from 'simpl-schema'; import SimpleSchema from 'simpl-schema';
import { Mongo } from 'meteor/mongo'; import { Mongo } from 'meteor/mongo';
import moment from 'moment';
/** /**
* this local collection keep tracks of all tabs of this application * this local collection keep tracks of all tabs of this application
...@@ -37,7 +38,7 @@ SimpleSchema.TabsCollection = new SimpleSchema({ ...@@ -37,7 +38,7 @@ SimpleSchema.TabsCollection = new SimpleSchema({
}, },
createdAt: { createdAt: {
type: Date, type: Date,
defaultValue: new Date(), defaultValue: moment().toDate(),
}, },
}); });
......
import SimpleSchema from 'simpl-schema'; import SimpleSchema from 'simpl-schema';
import { Mongo } from 'meteor/mongo'; import { Mongo } from 'meteor/mongo';
import moment from 'moment';
/** /**
* this collection is temporaire for testsearch * this collection is temporaire for testsearch
...@@ -25,7 +26,7 @@ SimpleSchema.testSearchCollection = new SimpleSchema({ ...@@ -25,7 +26,7 @@ SimpleSchema.testSearchCollection = new SimpleSchema({
}, },
createdAt: { createdAt: {
type: Date, type: Date,
defaultValue: new Date(), defaultValue: moment().toDate(),
}, },
}); });
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { FlowRouter } from 'meteor/kadira:flow-router'; import { FlowRouter } from 'meteor/kadira:flow-router';
import { BlazeLayout } from 'meteor/kadira:blaze-layout'; 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 layout templates
import '/imports/ui/layouts/main/main'; import '/imports/ui/layouts/main/main';
......
...@@ -4,7 +4,7 @@ import { Template } from 'meteor/templating'; ...@@ -4,7 +4,7 @@ import { Template } from 'meteor/templating';
import { Session } from 'meteor/session'; import { Session } from 'meteor/session';
import formSearchSchema from '/imports/api/search/formSearchSchema'; import formSearchSchema from '/imports/api/search/formSearchSchema';
import '/imports/api/search/formSearchHooks'; 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'; import '/imports/ui/components/resultSearch/resultSearch';
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating'; import { Template } from 'meteor/templating';
import notifsCollection from '/imports/api/notif/notifsCollection'; import notifsCollection from '/imports/api/notif/notifsCollection';
import { displayNotif } from '/imports/api/notif/notif'; import { displayNotif } from '/imports/api/notif/methods';
import './sidebar.html'; import './sidebar.html';
...@@ -14,7 +14,7 @@ Template.sidebarLayoutTpl.onCreated(() => { ...@@ -14,7 +14,7 @@ Template.sidebarLayoutTpl.onCreated(() => {
const query = notifsCollection.find({}); const query = notifsCollection.find({});
query.observeChanges({ query.observeChanges({
added(item, id, fields) { added(item, id, fields) {
// console.log(id); console.log(id);
displayNotif(id); displayNotif(id);
}, },
}); });
......
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating'; import { Template } from 'meteor/templating';
import displayNotif from '/imports/api/notif/notif'; import { displayNotif } from '/imports/api/notif/methods';
import './add.html'; import './add.html';
......
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating'; import { Template } from 'meteor/templating';
import { displayNotif } from '/imports/api/notif/methods';
import displayNotif from '/imports/api/notif/notif';
import '/imports/tabular/configClient'; import '/imports/tabular/configClient';
import './list.html'; import './list.html';
......
...@@ -8,6 +8,7 @@ import '../../../components/tabs/tabs'; ...@@ -8,6 +8,7 @@ import '../../../components/tabs/tabs';
import './main/main'; import './main/main';
import './site/site'; import './site/site';
import './api/api'; import './api/api';
import './reseau/reseau';
import './indexation.html'; import './indexation.html';
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { Template } from 'meteor/templating'; import { Template } from 'meteor/templating';
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import swal from 'sweetalert2'; import swal from 'sweetalert2';
import { displayNotif } from '/imports/api/notif/notif.js'; import { displayNotif } from '/imports/api/notif/methods';
import './main.html'; import './main.html';