Skip to content

Commit

Permalink
excel dates and auth uncomment
Browse files Browse the repository at this point in the history
  • Loading branch information
whrrmydragons committed Oct 4, 2018
1 parent 78e106d commit 96f95ee
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 12 deletions.
13 changes: 9 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/core/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"postinstall": "bower install"
},
"dependencies": {
"request": "^2.87.0"
"request": "^2.88.0"
},
"license": "MIT",
"_id": "mean-admin@0.0.3",
Expand Down
39 changes: 34 additions & 5 deletions packages/custom/icu/server/controllers/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ function GivenTasksOfNextWeekSummary(user) {
* @param {*} columns what columns to display in the excel
* @returns a promise that returns workbook
*/
async function tasksToExcelServiceFormat(tasks,columns){
async function tasksToExcelServiceFormat(tasks,columns,datesColumns){
let UpdateModel = require('../models/update');
tasks = _.map(tasks,task=>task._doc);
let filteredTasks = _.filter(tasks,task=>task.title);
Expand All @@ -972,7 +972,7 @@ async function tasksToExcelServiceFormat(tasks,columns){
.populate('creator', null, 'User');
let row = [
title,
due&&due.toLocaleString().substr(0, due.toLocaleString().indexOf(' ')), // * gives the date as "year-month-day time" and removes time
//due&&due.toLocaleString().substr(0, due.toLocaleString().indexOf(' ')), // * gives the date as "year-month-day time" and removes time
status,
assign&&assign.name,
_.map(watchers,watcher=>watcher.name).join("\n"),
Expand All @@ -987,7 +987,31 @@ async function tasksToExcelServiceFormat(tasks,columns){

return row;
}));
return excelService.json2workbook({"rows":taskArray,columns,"columnsBold":true});
let taskDatesArray = await Promise.all(_.map(filteredTasks,async (task)=>{
let {
_id,
due,
} = task;
//console.log("%^$^%$^%$^");
//console.log(task);
let updates = await UpdateModel
.find({
issueId: _id,
type: "comment"
})
.populate('creator', null, 'User');
let lastUpdate = _.last(updates);
let lastUpdateDate = lastUpdate&&lastUpdate.updated

let row = [
due,//&&due.toLocaleString().substr(0, due.toLocaleString().indexOf(' ')), // * gives the date as "year-month-day time" and removes time
lastUpdateDate// _.map(updates,(update=>`:${update.updated&&update.updated.toLocaleString().substr(0, update.updated.toLocaleString().indexOf(' '))} - ${update.creator.name}`+"\n"+`${update.description}`) ).join("\n"),
];


return row;
}));
return excelService.json2workbookWithDates({"rows":taskArray,dates:taskDatesArray,columns,datesColumns,"columnsBold":true});
}


Expand All @@ -999,12 +1023,17 @@ async function tasksToExcelServiceFormat(tasks,columns){
res.setHeader("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
//setting the name of the file to be downloaded
res.attachment("Summary.xlsx");
let columns = ["כותרת","תג"+"\""+"ב","סטטוס","אחראי","משתתפים","תיאור","יוצר המשימה","שם דיון","שם פרוייקט","עדכונים","תגיות"]
// let columns = ["כותרת","תג"+"\""+"ב","סטטוס","אחראי","משתתפים","תיאור","יוצר המשימה","שם דיון","שם פרוייקט","עדכונים","תגיות"]
let columns = ["כותרת","סטטוס","אחראי","משתתפים","תיאור","יוצר המשימה","שם דיון","שם פרוייקט","עדכונים","תגיות"]
let datesColumns = ["תג"+"\""+"ב","תאריך תגובה אחרון"]
let tasks = req.locals.result;
tasksToExcelServiceFormat(tasks,columns).then(summary=>{
tasksToExcelServiceFormat(tasks,columns,datesColumns).then(summary=>{
res.send(summary);
});
};




exports.byAssign = byAssign;
exports.myTasksStatistics = myTasksStatistics;
2 changes: 1 addition & 1 deletion packages/custom/icu/server/routes/icu.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = function(Icu, app) {

// /^((?!\/hi\/).)*$/ all routes without '/api/hi/*'
app.route(/^((?!\/hi\/).)*$/).all(locals);
//omri uncomment app.route(/^((?!\/hi\/).)*$/).all(authorization);
app.route(/^((?!\/hi\/).)*$/).all(authorization);

//app.route(/^((?!\/hi\/).)*$/).all(authorization, socket);

Expand Down
59 changes: 58 additions & 1 deletion packages/custom/icu/server/services/excel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,66 @@ json structure:
columnsBold:true\false
columns:[col1,col2,col3],
array of arrays=== rows:[row1,row2,row3]
dates === rows:[row1,row2,row3]
datesColumns:[dcol1,dcol2]
}
aoa = aray of arays = [row1,row2,row3,...] =example= [row1=[1,2,3],row2=[4,5,6],...]
*/

//same as json for json2workbook with additional datesColumns and aoa of dates
function json2workbookWithDates(json){
return XlsxPopulate.fromBlankAsync()
.then((workbook)=>{
let regColumnsLength = json.columns.length;
let datesColumnsLength = json.datesColumns.length;

let sheet = workbook.sheet("Sheet1");

for(let j = 0;j<regColumnsLength+datesColumnsLength;j++){
if(j<regColumnsLength){
sheet.row(1).cell(j+1).value(striptags(json.columns[j]))
sheet.row(1).cell(j+1).style({
"bold":json.columnsBold,
"fontFamily":"Arial",
});}
else{
sheet.row(1).cell(j+1).value(json.datesColumns[j-regColumnsLength]);
sheet.row(1).cell(j+1).style({
"bold":json.columnsBold,
"fontFamily":"Arial",
});
}
}

for(let i = 0;i<json.rows.length;i++){
for(let j =0;j<json.rows[i].length+json.dates[i].length;j++){
let cell = sheet.row(i+2).cell(j+1);
if(j<json.rows[i].length)
cell.value(striptags(json.rows[i][j]));
else {
cell.value(json.dates[i][j-json.rows[i].length]);
cell.style("numberFormat","dddd, mmmm dd, yyyy");
}


cell.style({
"fontFamily":"Arial",
"wrapText":true,
"verticalAlignment":"top",
"horizontalAlignment":"right",
"textDirection":"left-to-right",
});
}}
return workbook.outputAsync();
})
.catch((err)=>{
console.log(err);
});

}



/**
*
*Takes a json repesentation of excel and returs a workbook
Expand Down Expand Up @@ -49,4 +105,5 @@ function json2workbook(json){
}


exports.json2workbook = json2workbook;
exports.json2workbook = json2workbook;
exports.json2workbookWithDates =json2workbookWithDates

0 comments on commit 96f95ee

Please sign in to comment.