Skip to content
This repository has been archived by the owner on Mar 7, 2018. It is now read-only.

Commit

Permalink
Merge pull request #102 from Smarker/trustedsources-final
Browse files Browse the repository at this point in the history
Trustedsources final
  • Loading branch information
Smarker committed Oct 18, 2017
2 parents a5852b8 + 6355834 commit 10acac9
Show file tree
Hide file tree
Showing 20 changed files with 646 additions and 1,020 deletions.
679 changes: 338 additions & 341 deletions package-lock.json

Large diffs are not rendered by default.

54 changes: 27 additions & 27 deletions package.json
Expand Up @@ -35,66 +35,66 @@
},
"devDependencies": {
"babel-eslint": "^7.2.3",
"eslint": "^4.6.1",
"eslint-config-react-app": "^2.0.0",
"eslint-plugin-flowtype": "^2.35.1",
"eslint": "^4.8.0",
"eslint-config-react-app": "^2.0.1",
"eslint-plugin-flowtype": "^2.39.1",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^7.3.0",
"mocha": "^3.1.2",
"eslint-plugin-react": "^7.4.0",
"mocha": "^3.5.3",
"react-scripts": "^0.8.4"
},
"peerDependencies": {
"react": "^15.4.2",
"react-dom": "^15.4.2"
},
"dependencies": {
"async": "^2.0.1",
"async": "^2.5.0",
"autosuggest-highlight": "^3.1.0",
"bootstrap": "^3.3.7",
"create-react-class": "^15.6.0",
"create-react-class": "^15.6.2",
"fbgraph": "^1.4.1",
"flux": "^3.1.0",
"flux": "^3.1.3",
"fluxxor": "^1.7.3",
"geo-viewport": "^0.2.1",
"geotile": "^0.1.6",
"leaflet": "^1.0.2",
"leaflet-draw": "^0.4.8",
"leaflet-geocoder-mapzen": "^1.7.1",
"leaflet.markercluster": "^1.0.0",
"leaflet.markercluster.layersupport": "^1.0.3",
"leaflet": "^1.2.0",
"leaflet-draw": "^0.4.12",
"leaflet-geocoder-mapzen": "^1.9.4",
"leaflet.markercluster": "^1.1.0",
"leaflet.markercluster.layersupport": "^1.0.5",
"lodash": "^4.17.4",
"material-ui": "^0.16.6",
"material-ui-superselectfield": "^0.1.4",
"moment": "^2.11.2",
"moment": "^2.19.0",
"numeral": "^1.5.3",
"prop-types": "^15.5.10",
"react": "^15.4.2",
"react-addons-create-fragment": "^15.4.1",
"react-addons-transition-group": "^15.4.2",
"prop-types": "^15.6.0",
"react": "^15.6.2",
"react-addons-create-fragment": "^15.6.2",
"react-addons-transition-group": "^15.6.2",
"react-autosuggest": "^7.0.1",
"react-bootstrap": "^0.31.3",
"react-data-grid": "^2.0.37",
"react-data-grid-addons": "^2.0.1",
"react-dom": "^15.4.2",
"react-data-grid": "^2.0.60",
"react-data-grid-addons": "^2.0.60",
"react-dom": "^15.6.2",
"react-grid-layout": "^0.13.9",
"react-highlight-words": "^0.6.0",
"react-infinite": "^0.10.0",
"react-konva": "^1.1.1",
"react-leaflet": "^1.6.5",
"react-konva": "^1.1.5",
"react-leaflet": "^1.7.1",
"react-leaflet-draw": "^0.16.0",
"react-leaflet-markercluster": "^1.1.6",
"react-list-view": "^1.0.0",
"react-progress-bar-plus": "^1.2.0",
"react-router": "^3.0.0",
"react-router": "^3.2.0",
"react-tabs": "^0.8.2",
"react-tagcloud": "^1.2.0",
"react-tap-event-plugin": "^2.0.1",
"react-tooltip": "^3.3.0",
"react-tooltip": "^3.3.1",
"react-treebeard": "^1.1.4",
"react-widgets": "^3.4.5",
"react-widgets": "^3.5.0",
"recharts": "^0.22.4",
"request": "^2.81.0",
"request": "^2.83.0",
"turf-bbox-polygon": "^3.0.12",
"turf-extent": "^1.0.4",
"turf-inside": "^3.0.12",
Expand Down
1 change: 1 addition & 0 deletions public/index.html
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8" />
<title>Fortis Dashboard</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/latest/css/bootstrap.min.css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet.draw/0.4.2/leaflet.draw.css"/>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet">
Expand Down
180 changes: 57 additions & 123 deletions src/actions/Admin/index.js
Expand Up @@ -8,6 +8,19 @@ function getListAfterRemove(listBeforeRemove, itemsRemoved, keyBy) {
}

const methods = {
restart_pipeline() {
const self = this;
AdminServices.restartPipeline((err, response, body) => ResponseHandler(err, response, body, (error, graphqlResponse) => {
if (graphqlResponse && !error) {
self.dispatch(constants.ADMIN.RESTART_PIPELINE, { response: graphqlResponse.restartPipeline });
} else {
const action = 'failed';
console.error(`Failed to restart pipeline`);
self.dispatch(constants.ADMIN.RESTART_PIPELINE, {action});
}
}));
},

load_blacklist() {
const self = this;
AdminServices.fetchBlacklists((err, response, body) => ResponseHandler(err, response, body, (error, graphqlResponse) => {
Expand Down Expand Up @@ -119,50 +132,6 @@ const methods = {
}));
},

save_twitter_accounts(siteName, twitterAccts) {
const self = this;
const mutationNameTwitterAcctModify = "modifyTwitterAccounts";

AdminServices.saveTwitterAccounts(siteName, twitterAccts, mutationNameTwitterAcctModify, (error, response, body) => {
if(!error && response.statusCode === 200 && body.data && body.data.streams) {
const action = 'saved';
const streams = body.data.streams;
self.dispatch(constants.ADMIN.LOAD_TWITTER_ACCOUNTS, {streams, action});
}else{
console.error(`[${error}] occured while processing message request`);
}
});
},

remove_twitter_accounts(siteName, twitterAccts) {
const self = this;
const mutationNameTwitterAcctModifyRemove = "removeTwitterAccounts";
AdminServices.saveTwitterAccounts(siteName, twitterAccts, mutationNameTwitterAcctModifyRemove, (error, response, body) => {
if(!error && response.statusCode === 200 && body.data && body.data.streams) {
const action = 'saved';
const streams = body.data.streams;
self.dispatch(constants.ADMIN.LOAD_TWITTER_ACCOUNTS, {streams, action});
}else{
console.error(`[${error}] occured while processing message request`);
}
});
},

load_twitter_accounts() {
const self = this;
AdminServices.fetchTwitterAccounts((err, response, body) => ResponseHandler(err, response, body, (error, graphqlResponse) => {
if (graphqlResponse && !error) {
const response = graphqlResponse ? graphqlResponse : [];
const action = false;
self.dispatch(constants.ADMIN.LOAD_TWITTER_ACCOUNTS, {response, action});
} else{
const error = 'Error, could not load twitter accounts for admin page';
self.dispatch(constants.ADMIN.LOAD_FAIL, { error });
}
}));
},


load_topics(translationLanguage) {
const self = this;
const dataStore = this.flux.stores.AdminStore.dataStore;
Expand All @@ -173,7 +142,7 @@ const methods = {
const action = "saved";
self.dispatch(constants.ADMIN.LOAD_TOPICS, {response, action});
} else {
let error = 'Error, could not load keywords for admin page';
const error = 'Error, could not load keywords for admin page';
self.dispatch(constants.ADMIN.LOAD_FAIL, { error });
}
}))
Expand All @@ -188,7 +157,7 @@ const methods = {
const topicsAfterSave = this.flux.stores.AdminStore.dataStore.watchlist;
self.dispatch(constants.ADMIN.LOAD_TOPICS, { action, response: topicsAfterSave});
} else {
let error = 'Error, could not load keywords for admin page';
const error = 'Error, could not load keywords for admin page';
self.dispatch(constants.ADMIN.LOAD_FAIL, { error });
}
}));
Expand All @@ -206,91 +175,56 @@ const methods = {
const topicsAfterRemove = getListAfterRemove(topicsBeforeRemove, topicsToRemove, 'topicid');
self.dispatch(constants.ADMIN.LOAD_TOPICS, { action, response: topicsAfterRemove });
} else {
let error = 'Error, could not remove keywords from admin page';
const error = 'Error, could not remove keywords from admin page';
self.dispatch(constants.ADMIN.LOAD_FAIL, { error });
}
}));
}
},

load_trusted_sources(pipelineKeys, sourceName) {
const self = this;
const dataStore = this.flux.stores.AdminStore.dataStore;
if (!dataStore.loading) {
AdminServices.fetchTrustedSources(pipelineKeys, sourceName, (err, response, body) => ResponseHandler(err, response, body, (error, graphqlResponse) => {
if (graphqlResponse && !error) {
const response = graphqlResponse.trustedSources.sources
const action = "saved";
self.dispatch(constants.ADMIN.LOAD_TRUSTED_SOURCES, {response, action});
} else {
let error = 'Error, could not load trusted sources for admin page';
self.dispatch(constants.ADMIN.LOAD_FAIL, { error });
}
}))
}
},

save_trusted_sources(sources) {
const self = this;
const dataStore = this.flux.stores.AdminStore.dataStore;
if (!dataStore.loading) {
AdminServices.saveTrustedSources(sources, (err, response, body) => ResponseHandler(err, response, body, (error, graphqlResponse) => {
if (graphqlResponse && !error) {
const trustedSourcesAfterSave = this.flux.stores.AdminStore.dataStore.trustedSources;
const action = 'saved';
self.dispatch(constants.ADMIN.LOAD_TRUSTED_SOURCES, {response: trustedSourcesAfterSave, action});
} else {
let error = 'Error, could not load trusted sources for admin page';
self.dispatch(constants.ADMIN.LOAD_FAIL, { error });
}
}))
}
},

remove_trusted_sources(sources) {
const self = this;
const dataStore = this.flux.stores.AdminStore.dataStore;
if (!dataStore.loading) {
AdminServices.removeTrustedSources(sources, (err, response, body) => ResponseHandler(err, response, body, (error, graphqlResponse) => {
if (graphqlResponse && !error) {
const action = 'saved';
const trustedSourcesBeforeRemove = this.flux.stores.AdminStore.dataStore.trustedSources;
const trustedSourcesRemoved = graphqlResponse.removeTrustedSources.sources
const trustedSourcesAfterRemove = getListAfterRemove(trustedSourcesBeforeRemove, trustedSourcesRemoved, 'rowKey');
self.dispatch(constants.ADMIN.LOAD_TRUSTED_SOURCES, {response: trustedSourcesAfterRemove, action});
} else {
let error = 'Error, could not load trusted sources for admin page';
self.dispatch(constants.ADMIN.LOAD_FAIL, { error });
}
}))
}
},
notifyDataGridTrustedSourcesLoaded() {
const self = this;
const action = "saved";
self.dispatch(constants.ADMIN.LOAD_TRUSTED_SOURCES, {action});
},

remove_keywords(siteId, deletedRows) {
const self = this;
save_trusted_sources(sources) {
const self = this;
const dataStore = this.flux.stores.DataStore.dataStore;
if (!dataStore.loading) {
AdminServices.saveTrustedSources(sources, (err, response, body) => ResponseHandler(err, response, body, (error, graphqlResponse) => {
if (graphqlResponse && !error) {
const trustedSourcesAfterSave = this.flux.stores.DataStore.dataStore.trustedSources;
const action = 'saved';
self.dispatch(constants.ADMIN.LOAD_TRUSTED_SOURCES, {action});
self.dispatch(constants.DASHBOARD.LOAD_TRUSTED_SOURCES, {response: trustedSourcesAfterSave});
} else {
const error = 'Error, could not load trusted sources for admin page';
self.dispatch(constants.ADMIN.LOAD_FAIL, { error });
}
}))
}
},

AdminServices.removeKeywords(siteId, deletedRows, (error, response, body) => {
if(!error && response.statusCode === 200 && body.data.removeKeywords) {
const response = body.data.removeKeywords.edges;
const action = 'saved';
self.dispatch(constants.ADMIN.LOAD_KEYWORDS, {response, action});
}else{
console.error(`[${error}] occured while processing message request`);
}
});
},
save_keywords(siteId, modifiedKeywords){
const self = this;
AdminServices.saveKeywords(siteId, modifiedKeywords, (error, response, body) => {
if(!error && response.statusCode === 200) {
const action = 'saved';
const response = body.data.addKeywords.edges;
self.dispatch(constants.ADMIN.LOAD_KEYWORDS, {response, action});
}else{
console.error(`[${error}] occured while processing message request`);
}
});
},
remove_trusted_sources(sources) {
const self = this;
const dataStore = this.flux.stores.DataStore.dataStore;
if (!dataStore.loading) {
AdminServices.removeTrustedSources(sources, (err, response, body) => ResponseHandler(err, response, body, (error, graphqlResponse) => {
if (graphqlResponse && !error) {
const action = 'saved';
const trustedSourcesBeforeRemove = this.flux.stores.DataStore.dataStore.trustedSources;
const trustedSourcesRemoved = graphqlResponse.removeTrustedSources.sources
const trustedSourcesAfterRemove = getListAfterRemove(trustedSourcesBeforeRemove, trustedSourcesRemoved, 'rowKey');
self.dispatch(constants.ADMIN.LOAD_TRUSTED_SOURCES, {action});
self.dispatch(constants.DASHBOARD.LOAD_TRUSTED_SOURCES, {response: trustedSourcesAfterRemove})
} else {
const error = 'Error, could not load trusted sources for admin page';
self.dispatch(constants.ADMIN.LOAD_FAIL, { error });
}
}))
}
},

publish_events(events){
AdminServices.publishCustomEvents(events, (err, response, body) => ResponseHandler(err, response, body, (error, graphqlResponse) => {
Expand Down
39 changes: 18 additions & 21 deletions src/actions/Dashboard/index.js
Expand Up @@ -28,13 +28,13 @@ function fetchCommonTerms(settings, callback, timespanType, fromDate, toDate, ca
const dataSources = toDataSources((streams && streams.streams) || []);

DashboardServices.getCommonTerms(timespanType, fromDate, toDate, configuration.targetBbox, configuration.defaultZoomLevel, category,
(error, response, body) => ResponseHandler(error, response, body, (err, topics) => {
if (!err) {
callback(null, Object.assign({}, { terms, dataSources }, { configuration }, topics ));
} else {
callback(err, null);
}
}));
(error, response, body) => ResponseHandler(error, response, body, (err, topics) => {
if (!err) {
callback(null, Object.assign({}, { terms, dataSources }, { configuration }, topics ));
} else {
callback(err, null);
}
}));
}

function fetchFullChartData(fromDate, toDate, periodType, dataSource, maintopic,
Expand All @@ -47,21 +47,18 @@ function fetchFullChartData(fromDate, toDate, periodType, dataSource, maintopic,
}

function fetchAllTrustedSources(resultsUnion, callback) {
const { dataSources } = resultsUnion;
const pipelineKeys = dataSources.get('all').sourceValues;

AdminServices.fetchTrustedSources(pipelineKeys, '', (trustedSourcesErr, response, body) => {
ResponseHandler(trustedSourcesErr, response, body, (err, data) => {
if (err) {
console.error(`Non-fatal error while fetching trusted sources: ${err}`)
callback(null, resultsUnion);
} else {
const trustedSources = data.trustedSources && data.trustedSources.sources;
resultsUnion.trustedSources = trustedSources;
callback(null, resultsUnion);
}
});
AdminServices.fetchTrustedSources((trustedSourcesErr, response, body) => {
ResponseHandler(trustedSourcesErr, response, body, (err, data) => {
if (err) {
console.error(`Non-fatal error while fetching trusted sources: ${err}`)
callback(null, resultsUnion);
} else {
const trustedSources = data.trustedSources && data.trustedSources.sources;
resultsUnion.trustedSources = trustedSources;
callback(null, resultsUnion);
}
});
});
}

function fetchInitialChartDataCB(resultUnion, fromDate, toDate, timespanType, category, callback) {
Expand Down

0 comments on commit 10acac9

Please sign in to comment.