Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/excel file import #198

Merged
merged 3 commits into from
Sep 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 27 additions & 21 deletions client/app/scripts/controllers/create-manual-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,35 +81,41 @@ angular.module('ShoppinPalApp').controller(

this.uploader.onAfterAddingFile = function (fileItem) {
var filename = fileItem.file.name;
var slicedFilename = filename.slice(0,-4);
var data = slicedFilename.split('-');
var re = /(?:\.([^.]+))?$/;
var fileExtension = re.exec(filename);

if (data[0]===undefined || data[1]===undefined) {
self.validUpload = false;
$spAlerts.addAlert('Filename is not valid', 'error', 5000);
}
else {
var storeName = data[0];
storeName = storeName.replace(/_/g, ' '); // . is treated as regex when
//console.log('regex with storeName', storeName);
if(fileExtension[1].toLowerCase() === 'csv'){
var slicedFilename = filename.slice(0,-4);
var data = slicedFilename.split('-');
if (data[0]===undefined || data[1]===undefined) {
self.validUpload = false;
$spAlerts.addAlert('Filename is not valid', 'error', 5000);
}
else {

var supplierName = data[1];
supplierName = supplierName.replace(/_/g, ' '); // . is treated as regex when
//console.log('regex with supplierName', supplierName);
var storeName = data[0];
storeName = storeName.replace(/_/g, ' '); // . is treated as regex when

if (storeExists(storeName,self.stores)) {
if (supplierExists(supplierName,self.suppliers)) {
self.validUpload = true;
var supplierName = data[1];
supplierName = supplierName.replace(/_/g, ' '); // . is treated as regex when

if (storeExists(storeName,self.stores)) {
if (supplierExists(supplierName,self.suppliers)) {
self.validUpload = true;
}
else {
self.validUpload = false;
$spAlerts.addAlert('Supplier Name is not valid', 'error', 5000);
}
}
else {
self.validUpload = false;
$spAlerts.addAlert('Supplier Name is not valid', 'error', 5000);
$spAlerts.addAlert('Store Name is not valid', 'error', 5000);
}
}
else {
self.validUpload = false;
$spAlerts.addAlert('Store Name is not valid', 'error', 5000);
}
}
else if(fileExtension[1].toLowerCase() === 'xls' || fileExtension[1].toLowerCase() === 'xlsx'){
self.validUpload = true;
}
};

Expand Down
2 changes: 1 addition & 1 deletion client/app/views/create-manual-order.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ <h2>New Stock Order</h2>
<div class="col-xs-8">
<input id="file-import-input"
type="file"
accept=".csv"
accept=".csv,.xls"
nv-file-select
uploader="orderController.uploader"/>
<span ng-if="orderController.uploader.queue.length===1 && orderController.validUpload">Ready for import: {{orderController.uploader.queue[0].file.name}}</span>
Expand Down
401 changes: 316 additions & 85 deletions common/models/container.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion common/models/report-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ module.exports = function(ReportModel) {
cb(error);
});

cb(null);
});
}
};
Expand Down
3 changes: 3 additions & 0 deletions common/models/store-mapping-model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function(StoreMappingModel) {

};
13 changes: 13 additions & 0 deletions common/models/store-mapping-model.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "StoreMappingModel",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
"supertest-as-promised": "2.0.1",
"underscore": "^1.7.0",
"vend-nodejs-sdk": "^1.0.13",
"winston": "^0.8.3"
"winston": "^0.8.3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shame on me!

"xlsx": "~0.8.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use absolute version numbers, it help lock things down and keep them predictable

"excel-stream": "~1.1.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use absolute version numbers, it help lock things down and keep them predictable

},
"optionalDependencies": {
"loopback-explorer": "^1.1.0"
Expand All @@ -50,7 +52,7 @@
"grunt-karma": "~0.6.2",
"grunt-localtunnel-me": "^0.1.1",
"grunt-loopback-sdk-angular": "^1.1.2",
"grunt-mustache-render":"1.9.2",
"grunt-mustache-render": "1.9.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this required?

"grunt-ngmin": "~0.0.3",
"grunt-open": "~0.2.3",
"grunt-protractor-runner": "~0.2.4",
Expand Down
59 changes: 59 additions & 0 deletions server/boot/create-store-mappings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict';

var debug = require('debug')('boot:create-store-mappings');

var Promise = require('bluebird');
var _ = require('underscore');


module.exports = createStoreMappings;

function createStoreMappings(app,cb){
var StoreModel = app.models.StoreModel;
var StoreMappingModel = app.models.StoreMappingModel;

var seed = null;
try {
seed = require('./seed.json');
if(process.env.SKIP_SEEDING) {
debug('Will skip the database seeding process');
return;
}
} catch (err) {
debug('Please configure your data in `seed.json`.');
debug('Copy `seed.json.template` to `seed.json` and replace the values with your own.');
cb(err);
}
if(seed){
debug('seed each store-mapping, one-by-one');
return Promise.map(
seed.storeConfigModels,
function (storeData) {

return Promise.map(
storeData.storeMappingModels,
function(oneMapping){
return StoreMappingModel.findOrCreate(
{where:{code:oneMapping.code}},
oneMapping
)
.spread(function(mappingModelInstance,created){
(created) ? debug('mapping created', 'StoreMappingModel', mappingModelInstance)
: debug('mapping found', 'StoreMappingModel', mappingModelInstance);
});
},
{concurrency:1}
)
},
{concurrency:1}
)
.then(function(){
debug('Done with seeding mappings');
cb();
})
.catch(function(err){
log.error('error',err);
cb(err);
});
}
}
4 changes: 4 additions & 0 deletions server/model-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,9 @@
"container": {
"dataSource": "storage",
"public": true
},
"StoreMappingModel": {
"dataSource": "db",
"public": false
}
}