退勤管理をslackで管理しようと考えています。
そこで「みやもとさん」を導入することになりました。
ですが、このアプリでは、1日に1度の出勤にしか対応しておりません。
デフォルトでは
このように出勤、退勤が管理されています。
このように横に1日何度かの出勤退勤を全て保存できるようにしたいと思っていますが、javascript初心者の私には難しいです。
どなたかご教授をお願い致します。
変更点はこのコードだと考えています...
javascript
1loadGSTimesheets = function () { 2 var GSTimesheets = function(spreadsheet, settings) { 3 this.spreadsheet = spreadsheet; 4 this.settings = settings; 5 this._sheets = {}; 6 7 this.scheme = { 8 columns: [ 9 { name: '日付' }, 10 { name: '出勤' }, 11 { name: '退勤' }, 12 { name: 'ノート' }, 13 ], 14 properties: [ 15 { name: 'DayOff', value: '土,日', comment: '← 月,火,水みたいに入力してください。アカウント停止のためには「全部」と入れてください。'}, 16 ] 17 }; 18 }; 19 20 GSTimesheets.prototype._getSheet = function(username) { 21 if(this._sheets[username]) return this._sheets[username]; 22 23 var sheet = this.spreadsheet.getSheetByName(username); 24 if(!sheet) { 25 sheet = this.spreadsheet.insertSheet(username); 26 if(!sheet) { 27 throw "エラー: "+sheetName+"のシートが作れませんでした"; 28 } 29 else { 30 // 中身が無い場合は新規作成 31 if(sheet.getLastRow() == 0) { 32 // 設定部の書き出し 33 var properties = [["Properties count", this.scheme.properties.length, null]]; 34 this.scheme.properties.forEach(function(s) { 35 properties.push([s.name, s.value, s.comment]); 36 }); 37 sheet.getRange("A1:C"+(properties.length)).setValues(properties); 38 39 // ヘッダの書き出し 40 var rowNo = properties.length + 2; 41 var cols = this.scheme.columns.map(function(c) { return c.name; }); 42 sheet.getRange("A"+rowNo+":"+String.fromCharCode(65 + cols.length - 1)+rowNo).setValues([cols]); 43 } 44 //this.on("newUser", username); 45 } 46 } 47 48 this._sheets[username] = sheet; 49 50 return sheet; 51 }; 52 53 GSTimesheets.prototype._getRowNo = function(username, date) { 54 if(!date) date = DateUtils.now(); 55 var rowNo = this.scheme.properties.length + 4; 56 var startAt = DateUtils.parseDate(this.settings.get("開始日")); 57 var s = new Date(startAt[0], startAt[1]-1, startAt[2], 0, 0, 0); 58 rowNo += parseInt((date.getTime()-date.getTimezoneOffset()*60*1000)/(1000*24*60*60)) - parseInt((s.getTime()-s.getTimezoneOffset()*60*1000)/(1000*24*60*60)); 59 return rowNo; 60 }; 61 62 GSTimesheets.prototype.get = function(username, date) { 63 var sheet = this._getSheet(username); 64 var rowNo = this._getRowNo(username, date); 65 var row = sheet.getRange("A"+rowNo+":"+String.fromCharCode(65 + this.scheme.columns.length - 1)+rowNo).getValues()[0].map(function(v) { 66 return v === '' ? undefined : v; 67 }); 68 69 return({ user: username, date: row[0], signIn: row[1], signOut: row[2], note: row[3] }); 70 }; 71 72 GSTimesheets.prototype.set = function(username, date, params) { 73 var row = this.get(username, date); 74 _.extend(row, _.pick(params, 'signIn', 'signOut', 'note')); 75 76 var sheet = this._getSheet(username); 77 var rowNo = this._getRowNo(username, date); 78 79 var data = [DateUtils.toDate(date), row.signIn, row.signOut, row.note].map(function(v) { 80 return v == null ? '' : v; 81 }); 82 sheet.getRange("A"+rowNo+":"+String.fromCharCode(65 + this.scheme.columns.length - 1)+rowNo).setValues([data]); 83 84 return row; 85 }; 86 87 GSTimesheets.prototype.getUsers = function() { 88 return _.compact(_.map(this.spreadsheet.getSheets(), function(s) { 89 var name = s.getName(); 90 return String(name).substr(0, 1) == '_' ? undefined : name; 91 })); 92 }; 93 94 GSTimesheets.prototype.getByDate = function(date) { 95 var self = this; 96 return _.map(this.getUsers(), function(username) { 97 return self.get(username, date); 98 }); 99 }; 100 101 // 休みの曜日を数字で返す 102 GSTimesheets.prototype.getDayOff = function(username) { 103 var sheet = this._getSheet(username); 104 return DateUtils.parseWday(sheet.getRange("B2").getValue()); 105 }; 106 107 return GSTimesheets; 108}; 109
javascript
1// 出勤 2 Timesheets.prototype.actionSignIn = function(username, message) { 3 if(this.datetime) { 4 var data = this.storage.get(username, this.datetime); 5 if(!data.signIn || data.signIn === '-') { 6 this.storage.set(username, this.datetime, {signIn: this.datetime}); 7 this.responder.template("出勤", username, this.datetimeStr); 8 } 9 else { 10 // 更新の場合は時間を明示する必要がある 11 if(!!this.time) { 12 this.storage.set(username, this.datetime, {signIn: this.datetime}); 13 this.responder.template("出勤更新", username, this.datetimeStr); 14 } 15 } 16 } 17 }; 18 19 // 退勤 20 Timesheets.prototype.actionSignOut = function(username, message) { 21 if(this.datetime) { 22 var data = this.storage.get(username, this.datetime); 23 if(!data.signOut || data.signOut === '-') { 24 this.storage.set(username, this.datetime, {signOut: this.datetime}); 25 this.responder.template("退勤", username, this.datetimeStr); 26 } 27 else { 28 // 更新の場合は時間を明示する必要がある 29 if(!!this.time) { 30 this.storage.set(username, this.datetime, {signOut: this.datetime}); 31 this.responder.template("退勤更新", username, this.datetimeStr); 32 } 33 } 34 } 35 };
回答1件
あなたの回答
tips
プレビュー