Skip to content

Commit

Permalink
Resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed Feb 28, 2017
2 parents 40c0f37 + 72227dc commit 5bf4ebb
Show file tree
Hide file tree
Showing 46 changed files with 2,013 additions and 441 deletions.
25 changes: 16 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"start": "./bin/cnc",
"start-electron": "electron ./dist/cnc/main",
"watch-dev": "webpack --watch --config webpack.backend-config.development.js",
"start-dev": "NODE_ENV=development ./bin/cnc -vvv -p 8000",
"start-dev": "NODE_ENV=development ./bin/cnc -vv -p 8000",
"dev": "npm run build-dev && npm run start-dev",
"prod": "npm run build-prod && NODE_ENV=production ./bin/cnc",
"lint": "npm run eslint && npm run stylint",
Expand All @@ -70,7 +70,9 @@
},
"mac": {
"category": "public.app-category.productivity",
"target": ["dmg"],
"target": [
"dmg"
],
"icon": "build/icon.icns"
},
"dmg": {
Expand All @@ -93,11 +95,15 @@
]
},
"win": {
"target": ["nsis"],
"target": [
"nsis"
],
"icon": "build/icon.ico"
},
"linux": {
"target": ["deb"]
"target": [
"deb"
]
}
},
"keywords": [
Expand All @@ -121,6 +127,7 @@
"@trendmicro/react-interpolate": "~0.5.1",
"@trendmicro/react-modal": "~0.6.0",
"@trendmicro/react-paginations": "~0.5.1",
"@trendmicro/react-toggle-switch": "~0.5.1",
"async": "~2.1.5",
"babel-runtime": "~6.23.0",
"bcrypt-nodejs": "0.0.3",
Expand Down Expand Up @@ -151,7 +158,7 @@
"gcode-toolpath": "~1.1.1",
"history": "~3.2.1",
"hogan.js": "~3.0.2",
"i18next": "~7.0.1",
"i18next": "~7.1.0",
"i18next-browser-languagedetector": "~1.0.1",
"i18next-express-middleware": "~1.0.2",
"i18next-node-fs-backend": "~0.1.3",
Expand Down Expand Up @@ -197,8 +204,8 @@
"redux": "~3.6.0",
"semver": "~5.3.0",
"serialport": "~4.0.7",
"serve-favicon": "~2.4.0",
"serve-static": "~1.11.2",
"serve-favicon": "~2.4.1",
"serve-static": "~1.12.0",
"session-file-store": "~1.0.0",
"sha1": "~1.1.1",
"shortid": "~2.2.6",
Expand Down Expand Up @@ -234,7 +241,7 @@
"css-loader": "~0.26.2",
"css-split-webpack-plugin": "~0.2.3",
"electron": "~1.4.15",
"electron-builder": "~14.4.0",
"electron-builder": "~14.5.1",
"electron-rebuild": "~1.5.7",
"eslint": "~3.16.1",
"eslint-config-trendmicro": "~0.5.1",
Expand Down Expand Up @@ -273,7 +280,7 @@
"stylint-loader": "~1.0.0",
"stylus": "~0.54.5",
"stylus-loader": "~2.5.0",
"tap": "~10.2.1",
"tap": "~10.2.2",
"text-table": "~0.2.0",
"transform-loader": "~0.2.4",
"url-loader": "~0.5.8",
Expand Down
224 changes: 224 additions & 0 deletions src/app/api/api.events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
import _ from 'lodash';
import uuid from 'uuid';
import settings from '../config/settings';
import config from '../services/configstore';
import {
ERR_BAD_REQUEST,
ERR_NOT_FOUND,
ERR_INTERNAL_SERVER_ERROR
} from '../constants';

export const fetchEvents = (req, res) => {
// Sort by `mtime` in descending order and by `event` in ascending order.
const events = _.orderBy(config.get('events', []), ['mtime', 'event'], ['desc', 'asc']);
const totalRecords = events.length;
let { page = 1, pageLength = 10 } = req.query;

page = Number(page);
pageLength = Number(pageLength);

if (!page || page < 1) {
page = 1;
}
if (!pageLength || pageLength < 1) {
pageLength = 10;
}
if (((page - 1) * pageLength) >= totalRecords) {
page = Math.ceil(totalRecords / pageLength);
}

const begin = (page - 1) * pageLength;
const end = Math.min((page - 1) * pageLength + pageLength, totalRecords);
const records = events.slice(begin, end).map((evt) => {
if (evt.id !== 0 && !evt.id) {
// Generate event id
evt.id = uuid.v4();
}
return {
id: evt.id,
mtime: evt.mtime,
enabled: evt.enabled,
event: evt.event,
trigger: evt.trigger,
// WARNING: The "command" parameter is deprecated and will be removed in a future release.
commands: (evt.commands || evt.command || '')
};
});

res.send({
pagination: {
page: page,
pageLength: pageLength,
totalRecords: totalRecords
},
records: records
});
};

export const getEvent = (req, res) => {
const evt = _.find(config.get('events', []), { id: req.params.id });

if (!evt) {
res.status(ERR_NOT_FOUND).send({
msg: 'Event not found'
});
return;
}

if (evt.id !== 0 && !evt.id) {
// Generate event id
evt.id = uuid.v4();
}

res.send({
id: evt.id,
mtime: evt.mtime,
enabled: evt.enabled,
event: evt.event,
trigger: evt.trigger,
// WARNING: The "command" parameter is deprecated and will be removed in a future release.
commands: (evt.commands || evt.command || '')
});
};

export const createEvent = (req, res) => {
const {
enabled = false,
event = '',
trigger = '',
commands = ''
} = { ...req.body };

if (!event) {
res.status(ERR_BAD_REQUEST).send({
msg: 'The "event" parameter must not be empty'
});
return;
}

if (!trigger) {
res.status(ERR_BAD_REQUEST).send({
msg: 'The "trigger" parameter must not be empty'
});
return;
}

if (!commands) {
res.status(ERR_BAD_REQUEST).send({
msg: 'The "commands" parameter must not be empty'
});
return;
}

try {
const events = config.get('events', []);
const evt = {
id: uuid.v4(),
mtime: new Date().getTime(),
enabled: !!enabled,
event: event,
trigger: trigger,
commands: commands
};

if (_.isArray(events)) {
events.push(evt);
config.set('events', events);
} else {
config.set('events', [evt]);
}

res.send({ id: evt.id, mtime: evt.mtime });
} catch (err) {
res.status(ERR_INTERNAL_SERVER_ERROR).send({
msg: 'Failed to save ' + JSON.stringify(settings.cncrc)
});
}
};

export const updateEvent = (req, res) => {
const id = req.params.id;
const events = config.get('events', []);
const evt = _.find(events, { id: id });

if (!evt) {
res.status(ERR_NOT_FOUND).send({
msg: 'Event not found'
});
return;
}

const {
enabled = evt.enabled,
event = evt.event,
trigger = evt.trigger,
// WARNING: The "command" parameter is deprecated and will be removed in a future release.
commands = (evt.commands || evt.command || '')
} = { ...req.body };

if (typeof enabled !== 'boolean') {
res.status(ERR_BAD_REQUEST).send({
msg: 'The "enabled" parameter must be a boolean value'
});
return;
}

if (!event) {
res.status(ERR_BAD_REQUEST).send({
msg: 'The "event" parameter must not be empty'
});
return;
}

if (!trigger) {
res.status(ERR_BAD_REQUEST).send({
msg: 'The "trigger" parameter must not be empty'
});
return;
}

// Skip checking whether the commands parameter is empty or not

try {
evt.mtime = new Date().getTime();
evt.enabled = enabled;
evt.event = event;
evt.trigger = trigger;
evt.commands = commands;
if (evt.command !== undefined) {
// WARNING: The "command" parameter is deprecated and will be removed in a future release.
delete evt.command;
}
config.set('events', events);

res.send({ id: evt.id, mtime: evt.mtime });
} catch (err) {
res.status(ERR_INTERNAL_SERVER_ERROR).send({
msg: 'Failed to save ' + JSON.stringify(settings.cncrc)
});
}
};

export const deleteEvent = (req, res) => {
const id = req.params.id;
const evt = _.find(config.get('events', []), { id: id });
if (!evt) {
res.status(ERR_NOT_FOUND).send({
msg: 'Event not found'
});
return;
}

try {
const events = _.filter(config.get('events', []), (evt) => {
return evt.id !== id;
});
config.set('events', events);

res.send({ id: evt.id });
} catch (err) {
res.status(ERR_INTERNAL_SERVER_ERROR).send({
msg: 'Failed to save ' + JSON.stringify(settings.cncrc)
});
}
};
4 changes: 2 additions & 2 deletions src/app/api/api.macros.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ERR_INTERNAL_SERVER_ERROR
} from '../constants';

export const getMacros = (req, res) => {
export const fetchMacros = (req, res) => {
const macros = _.map(config.get('macros', []), (macro) => {
const { id, name, content } = macro;

Expand Down Expand Up @@ -39,7 +39,7 @@ export const getMacro = (req, res) => {
});
};

export const addMacro = (req, res) => {
export const createMacro = (req, res) => {
const { name, content } = { ...req.body };

try {
Expand Down

0 comments on commit 5bf4ebb

Please sign in to comment.