Commit e92aa55c authored by Nacim Goura's avatar Nacim Goura

modif notif WP

parent 87a03dc3
......@@ -17,7 +17,7 @@ standard-minifier-css@1.3.4 # CSS minifier run for production mode
standard-minifier-js@2.1.0 # 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
fourseven:scss # Compile scss to css
fourseven:scss@4.5.0 # Compile scss to css
fortawesome:fontawesome # pretty icon
# package for view
......@@ -47,3 +47,4 @@ dynamic-import
aldeed:tabular
ajduke:bootstrap-tagsinput
percolate:synced-cron
matb33:collection-hooks
......@@ -55,6 +55,7 @@ launch-screen@1.1.1
livedata@1.0.18
localstorage@1.1.0
logging@1.1.17
matb33:collection-hooks@0.8.4
meteor@1.6.1
meteor-base@1.1.0
minifier-css@1.2.16
......
import { AutoForm } from 'meteor/aldeed:autoform';
import displayNotif from '/imports/api/notif/notif.js';
import { displayNotif } from '/imports/api/notif/notif.js';
const hooksFormApiCrawl = {
onSuccess(formType, result) {
displayNotif({
type: 'success',
title: 'Indexation : ',
message: `Indexation de ${result.api.idPage} pour l\'api ${result.api.type} fini avec succès avec ${result.index.items.length} urls indexées!`,
Meteor.call('addNotif', {
type: 'info',
title: 'Indexation API : ',
message: `Début de l\'indexation pour ${result.idPage}!`,
save: true,
});
},
onError(formType, error) {
displayNotif({
Meteor.call('addNotif', {
type: 'error',
title: 'Indexation : ',
title: 'Indexation API : ',
message: error.reason ? error.reason : error,
save: true,
});
......
......@@ -2,17 +2,18 @@
import CrawlFacebook from './crawlFacebook';
import CrawlTwitter from './crawlTwitter';
export default class crawlWebsite {
export default class crawlApi {
constructor(config) {
constructor() {
console.log('init crawl api!');
}
init(config) {
switch (config.type) {
case 'facebook':
return new CrawlFacebook(config);
case 'twitter':
return new CrawlTwitter(config);
case 'instagram':
break;
default:
throw new Meteor.Error('Error', 'Aucun type pour l\'API indiqué');
}
......
import { AutoForm } from 'meteor/aldeed:autoform';
import displayNotif from '/imports/api/notif/notif.js';
import { displayNotif } from '/imports/api/notif/notif.js';
const hooksFormWebsiteCrawl = {
onSuccess(formType, result) {
displayNotif({
Meteor.call('addNotif', {
type: 'success',
title: 'Indexation : ',
message: `Indexation fini avec succès avec ${result.index.items.length} urls indexées!`,
......@@ -12,7 +12,7 @@ const hooksFormWebsiteCrawl = {
});
},
onError(formType, error) {
displayNotif({
Meteor.call('addNotif', {
type: 'error',
title: 'Indexation : ',
message: error.reason ? error.reason : error,
......
......@@ -19,15 +19,14 @@ Meteor.methods({
},
indexWebsite(url) {
check(url, String);
this.unblock();
const index = new IndexWebsite();
return index.indexationWebsite(url);
},
indexApi(data) {
check(data, Object);
formApiCrawlSchema.validate(data);
this.unblock();
const index = new IndexApi();
return index.indexationApi(data);
index.indexationApi(data);
return data;
},
});
......@@ -9,15 +9,13 @@ export default class IndexApi extends IndexGeneric {
* @param data
* @returns Promise
*/
async indexationApi(data) {
return new CrawlApi(data)
.then(dataToIndex => new Promise(async resolve => resolve({
index: await this.indexByBulk(dataToIndex),
dataForm: {
api: data,
},
})))
.catch((error) => {
indexationApi(data) {
const crawlApi = new CrawlApi();
crawlApi.init(data)
.then((dataToIndex) => {
this.indexByBulk(dataToIndex)
.then(result => this.notifyUser(result));
}).catch((error) => {
throw error;
});
}
......
import { Meteor } from 'meteor/meteor';
import indexationElastic from '/imports/libs/elasticsearch/elasticsearch';
import configElastic from './elasticSearchConfig';
import configElastic from '/imports/libs/elasticsearch/elasticSearchConfig';
import { addNotif } from '/imports/api/notif/methods';
const esIndex = Meteor.settings.private.elasticsearch.esIndex;
const esType = Meteor.settings.private.elasticsearch.esType;
......@@ -37,87 +38,9 @@ export default class IndexGeneric {
}
/**
* search
* @param term
* @returns {promise}
* Add element on collection to warn the user of the end
*/
search(term) {
const params = {
from: 0,
size: 10,
};
if (term) {
/**
*
* common ( sépare les tokens les plus présents dans l’index des autres, et ne les utilise que pour améliorer la pertinence )
* fuzziness (permet une recherche même avec des fautes)
*/
params.query = {
bool: {
must: [
{
multi_match: {
query: term,
fuzziness: 'AUTO',
fields: [
'description',
'description.stemmed',
'body',
'body.stemmed',
'urlText',
'urlText.stemmed',
'url',
],
},
},
],
should: [
{
multi_match: {
query: term,
fuzziness: 'AUTO',
fields: [
'title',
'title.stemmed',
'url',
'breadcrumb',
'h1',
'h2',
'html',
],
},
},
],
minimum_should_match: 1,
boost: 2.0,
},
};
}
return indexationElastic.search(esIndex, esType, params);
}
/**
* autocompletion
* @param term
* @returns {promise}
*/
autoComplete(term) {
let params = {};
if (term) {
params = {
suggest: {
prefix: term,
completion: {
field: 'title_suggest',
size: 25,
},
},
};
}
return indexationElastic.suggest(esIndex, params);
notifyUser(result) {
addNotif(result);
}
}
......@@ -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/notif.js';
const hooksFormLogin = {
onSubmit: (insertDoc, updateDoc, currentDoc) => {
......
import { Meteor } from 'meteor/meteor';
import notifsCollection from './notifsCollection';
import notifsCollection from '/imports/api/notif/notifsCollection';
export function addNotif(notif) {
notif.userId = this.userId;
......
......@@ -2,7 +2,11 @@
import { Meteor } from 'meteor/meteor';
import iziToast from 'izitoast';
export default function (options) {
/**
* display notif for user
* @param options
*/
export function displayNotif(options) {
this.options = {
position: 'topCenter',
};
......@@ -13,13 +17,5 @@ export default function (options) {
Object.assign(this.options, options);
iziToast[options.type](this.options);
if (this.options.type === 'error') {
this.options.type = 'danger';
}
if (this.options.save === true) {
Meteor.call('addNotif', this.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
......@@ -12,7 +11,7 @@ const notifsCollection = new Mongo.Collection('notifs');
SimpleSchema.notifsCollection = new SimpleSchema({
type: {
type: String,
allowedValues: ['info', 'success', 'warning', 'danger'],
allowedValues: ['info', 'success', 'warning', 'danger', 'error'],
},
title: {
type: String,
......@@ -22,7 +21,7 @@ SimpleSchema.notifsCollection = new SimpleSchema({
},
createdAt: {
type: Date,
defaultValue: moment().toDate(),
defaultValue: new Date(),
},
userId: {
type: String,
......
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,
createdAt: {
$gte: moment().subtract(5, 'm').toISOString(),
$lt: moment().add(5, 'm').toISOString(),
},
});
});
......@@ -8,10 +8,8 @@ export default new SimpleSchema({
type: String,
required: false,
},
term: {
searchTerm: {
label: false,
type: String,
},
afterDate: {
type: Date,
},
}, { tracker: Tracker });
......@@ -2,13 +2,15 @@
import { check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';
import _ from 'lodash';
import IndexGeneric from '/imports/api/indexation/server/indexGeneric';
import Search from '/imports/api/search/server/search';
import formSearchSchema from '/imports/api/search/formSearchSchema';
Meteor.methods({
searchByTerm(term) {
check(term, String);
const index = new IndexGeneric();
return index.search(term)
searchByTerm(data) {
check(data, Object);
formSearchSchema.validate(data);
const search = new Search();
return search.search(data.searchTerm)
.then(result => ({
total: result.hits.total,
list: _.map(result.hits.hits, '_source'),
......@@ -20,8 +22,8 @@ Meteor.methods({
},
autoCompletion(term) {
check(term, String);
const index = new IndexGeneric();
return index.autoComplete(term)
const search = new Search();
return search.autoComplete(term)
.then((result) => {
if (result.suggest) {
return _.take(_.map(result.suggest[0].options, 'text'), 5);
......
import indexationElastic from '/imports/libs/elasticsearch/elasticsearch';
const esIndex = Meteor.settings.private.elasticsearch.esIndex;
const esType = Meteor.settings.private.elasticsearch.esType;
export default class Search {
constructor() {
console.log('search');
}
/**
* search
* @param term
* @returns {promise}
*/
search(term) {
const params = {
from: 0,
size: 10,
};
if (term) {
/**
*
* common ( sépare les tokens les plus présents dans l’index des autres, et ne les utilise que pour améliorer la pertinence )
* fuzziness (permet une recherche même avec des fautes)
*/
params.query = {
bool: {
must: [
{
multi_match: {
query: term,
fuzziness: 'AUTO',
fields: [
'description',
'description.stemmed',
'body',
'body.stemmed',
'urlText',
'urlText.stemmed',
'url',
],
},
},
],
should: [
{
multi_match: {
query: term,
fuzziness: 'AUTO',
fields: [
'title',
'title.stemmed',
'url',
'breadcrumb',
'h1',
'h2',
'html',
],
},
},
],
minimum_should_match: 1,
boost: 2.0,
},
};
}
return indexationElastic.search(esIndex, esType, params);
}
/**
* autocompletion
* @param term
* @returns {promise}
*/
autoComplete(term) {
let params = {};
if (term) {
params = {
suggest: {
prefix: term,
completion: {
field: 'title_suggest',
size: 25,
},
},
};
}
return indexationElastic.suggest(esIndex, params);
}
}
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
......@@ -38,7 +37,7 @@ SimpleSchema.TabsCollection = new SimpleSchema({
},
createdAt: {
type: Date,
defaultValue: moment().toDate(),
defaultValue: new Date(),
},
});
......
......@@ -2,7 +2,6 @@
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import _ from 'lodash';
import moment from 'moment';
import testSearchCollection from '/imports/api/testSearch/testSearchCollection';
export function addTest(test) {
......@@ -29,7 +28,7 @@ export function addTest(test) {
testSearchCollection.update(oldTest[0]._id, {
$set: {
urlPosition: test.urlPosition,
createdAt: moment().toDate(),
createdAt: new Date().toISOString(),
},
});
} else {
......
import SimpleSchema from 'simpl-schema';
import { Mongo } from 'meteor/mongo';
import moment from 'moment';
/**
* this collection is temporaire for testsearch
......@@ -26,7 +25,7 @@ SimpleSchema.testSearchCollection = new SimpleSchema({
},
createdAt: {
type: Date,
defaultValue: moment().toDate(),
defaultValue: new Date(),
},
});
......
......@@ -5,3 +5,4 @@ import 'bootstrap-sass';
import './routes';
moment.locale('fr');
......@@ -17,7 +17,7 @@ import '/imports/ui/pages/not-found/not-found';
import '/imports/ui/pages/admin/indexation/indexation';
import '/imports/ui/pages/admin/account/account';
import '/imports/ui/pages/admin/statistique/statistique';
import '/imports/ui/pages/admin/notif/notif';
import '/imports/ui/pages/notif/notif';
// Set up all routes in the app
import './adminRoutes';
......
......@@ -4,6 +4,7 @@ import '/imports/api/indexation/methods';
import '/imports/api/account/methods';
import '/imports/api/config/methods';
import '/imports/api/notif/methods';
import '/imports/api/notif/publications';
import '/imports/api/testSearch/methods';
import '/imports/api/search/methods';
import '/imports/tabular/tabularUser';
......
......@@ -3,10 +3,9 @@
<!-- Template searchTpl -->
<div class="autocomplete-holder">
<form role="search" class="form-horizontal" id="formSearch">
{{#autoForm id="formSearch" schema=formSearchSchema type="method" meteormethod="searchByTerm" resetOnSuccess=false}}
<div class="input-group">
<input id="searchResult" type="search" class="form-control" placeholder="Effectuer votre recherche..."
name="searchTerm">
{{> afQuickField name='searchTerm' placeholder="Recherche..."}}
<span class="input-group-btn">
<button type="submit" class="btn btn-primary">
<i class="fa fa-search"></i>
......@@ -24,7 +23,7 @@
</div>
{{/if}}
-->
</form>
{{/autoForm}}
</div>
{{> resultSearchTpl ""}}
......
......@@ -2,6 +2,8 @@
import { Meteor } from 'meteor/meteor';
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 '/imports/ui/components/resultSearch/resultSearch';
......@@ -10,10 +12,13 @@ import './search.html';
Template.searchTpl.helpers({
listAutoCompleteResults: () => Session.get('autoCompleteResults'),
formSearchSchema() {
return formSearchSchema;
},
});
Template.searchTpl.events({
'submit #formSearch': (event) => {
/* 'submit #formSearch': (event) => {
event.preventDefault();
const term = event.target.searchTerm.value;
......@@ -31,15 +36,15 @@ Template.searchTpl.events({
});
},
'input #searchResult': (event) => {
/* event.preventDefault();
event.preventDefault();
const term = event.target.value;
Meteor.callPromise('autoCompletion', term)
.then((results) => {
Session.set('autoCompleteResults', results);
});*/
},
});
}, */
'click .autocomplete-title': (event) => {
event.preventDefault();
......
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 './sidebar.html';
/**
* observe changement in collection for display notif
*/
Template.sidebarLayoutTpl.onCreated(() => {
Meteor.subscribe('notif');
const query = notifsCollection.find({});
query.observeChanges({
added(item, id, fields) {
// console.log(id);
displayNotif(id);
},
});
});
......@@ -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/notif.js';
import './main.html';
......@@ -20,14 +20,14 @@ Template.mainIndexationTpl.events({
}).then(() => {
Meteor.callPromise('initIndexElastic')
.then(() => {
displayNotif({
Meteor.call('addNotif', {
type: 'success',
title: 'Indexation : ',
message: 'ElasticSearch à été initialisé correctement!',
save: true,
});
}).catch((error) => {
displayNotif({
Meteor.call('addNotif', {
type: 'error',
title: 'Indexation : ',
message: error.reason ? error.reason : error,
......
......@@ -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/notif.js';
import formWebsiteCrawlSchema from '/imports/api/crawl/website/formWebsiteCrawlSchema';
import '/imports/api/crawl/website/formWebsiteCrawlHooks';
......
......@@ -6,7 +6,5 @@
{{> searchTpl ""}}
</div>
{{> resultSearchTpl ""}}
</template>
......@@ -55,9 +55,9 @@ amdefine@>=0.0.4:
version "1.0.1"
resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5"
ansi-escapes@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-2.0.0.tgz#5bae52be424878dd9783e8910e3fc2922e83c81b"
ansi-escapes@^1.1.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-1.4.0.tgz#d3a8a83b319aa67793662b13e761c7911422306e"
ansi-regex@^2.0.0:
version "2.1.1"
......@@ -84,9 +84,9 @@ argparse@^1.0.7:
dependencies:
sprintf-js "~1.0.2"