Guest User

Untitled

a guest
Feb 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.07 KB | None | 0 0
  1. class NextAction < ActiveRecord::Base
  2. #with (modelFor('Action')) {
  3. # belongsTo('Context');
  4. # belongsTo('Project');
  5. # validatesPresenceOf('name');
  6. #}
  7. belongs_to :context
  8. belongs_to :project
  9. validates_presence_of :name
  10. acts_as_list :scope => :context_id
  11. #
  12. #Action.findPending = function(conditions) {
  13. # if (conditions != null)
  14. # conditions = ' AND ' + conditions;
  15. # else
  16. # conditions = '';
  17. # return Action.findBySql("SELECT Action.*, Context.name AS cname" +
  18. # " FROM Action LEFT OUTER JOIN Context" +
  19. # " ON Action.contextId = Context.id" +
  20. # " WHERE Action.completedAt IS NULL" + conditions +
  21. # " ORDER BY cname ASC," +
  22. # " Action.position ASC, Action.name ASC");
  23. #}
  24. def find_pending(conditions='')
  25. if conditions
  26. find_all_by_completed_at nil, :conditions => conditions, :order => "Context.name ASC,position ASC,name ASC"
  27. else
  28. find_all_by_completed_at nil,:order=>"Context.name ASC, position ASC, name ASC"
  29. end #endif
  30. end #end find_pending
  31.  
  32. #Action.findCompleted = function() {
  33. # return Action.findBySql("SELECT Action.*, Context.name AS cname" +
  34. # " FROM Action LEFT OUTER JOIN Context" +
  35. # " ON Action.contextId = Context.id" +
  36. # " WHERE Action.completedAt IS NOT NULL" +
  37. # " ORDER BY Action.completedAt DESC, Action.name ASC")
  38. #}
  39. #
  40. def find_completed()
  41. find_all_by_completed_at !nil, :order => "completed_at DESC, name ASC"
  42. end #end find_completed
  43. #// Repeating actions encoding:
  44. #// code
  45. #// num of args
  46. #// description
  47. #// example
  48. #// w: 1, next day-of-week: Every _Sunday_
  49. #// m: 1, next day-of-month: On the _10th_ day of every month
  50. #// n: 2, nth day-of-week: On the _1st_ _Sunday_ of each month
  51. #// y: 2, day-of-year: On _1_/_20_ of each year (mm/dd)
  52. #// a: 1, add-days: _14_ days after each time the task is completed
  53. #//
  54. #Action.repeatType = {
  55. # '' : { // Do not repeat.
  56. # numArgs : 0,
  57. # toSummary : function() {
  58. # return '';
  59. # },
  60. # calcNextDate : function(info, date) {
  61. # return null;
  62. # }
  63. # },
  64. # 'w' : { // Next day-of-week: Every _Sunday_.
  65. # numArgs : 1,
  66. # toSummary : function(type, w1) {
  67. # return 'every ' + dayOfWeekChoices[w1][0];
  68. # },
  69. # calcNextDate : function(info, date) {
  70. # date.setDate(date.getDate() + (7 - date.getDay()) + info.w1);
  71. # return date;
  72. # }
  73. # },
  74. # 'm' : { // Next day-of-month: On the _10th_ day of every month.
  75. # numArgs : 1,
  76. # toSummary : function(type, m1) {
  77. # return 'monthly, on day ' + m1;
  78. # },
  79. # calcNextDate : function(info, date) {
  80. # date.setMonth(date.getMonth() + 1);
  81. # date.setDate(info.m1);
  82. # return date;
  83. # }
  84. # },
  85. # 'n' : { // Nth day-of-week: On the _1st_ _Sunday_ of each month.
  86. # numArgs : 2,
  87. # toSummary : function(type, n1, n2) {
  88. # return 'monthly, on the ' + weekOfMonthChoices[n1 - 1][0] + ' ' + dayOfWeekChoices[n2][0];
  89. # },
  90. # calcNextDate : function(info, date) {
  91. # date.setMonth(date.getMonth() + 1);
  92. # date.setDate(1);
  93. # var dayOfWeek = info.n2;
  94. # if (dayOfWeek < date.getDay())
  95. # dayOfWeek = dayOfWeek + 7;
  96. # date.setDate(date.getDate() + dayOfWeek - date.getDay());
  97. # date.setDate(date.getDate() + (7 * (info.n1 - 1)));
  98. # return date;
  99. # }
  100. # },
  101. # 'y' : { // Day-of-year: On _1_/_20_ of each year (mm/dd).
  102. # numArgs : 2,
  103. # toSummary : function(type, y1, y2) {
  104. # return 'yearly, on ' + y1 + '/' + y2;
  105. # },
  106. # calcNextDate : function(info, date) {
  107. # date.setFullYear(date.getFullYear() + 1);
  108. # date.setMonth(info.y1 - 1);
  109. # date.setDate(info.y2);
  110. # return date;
  111. # }
  112. # },
  113. # 'a' : { // Add-days: _14_ days after each time the Action is completed.
  114. # numArgs : 1,
  115. # toSummary : function(type, a1) {
  116. # return a1 + ' days after completion';
  117. # },
  118. # calcNextDate : function(info, date) {
  119. # date.setDate(date.getDate() + info.a1);
  120. # return date;
  121. # }
  122. # }
  123. #}
  124. def repeat_type()
  125. # repeat_hash = {
  126. # :none => {#Do not repeat
  127. # :to_summary => lambda {|| return ''},
  128. # :calc_next_date => lambda {|info| return nil}
  129. # },
  130. # :w => {#Next day of week, every sunday
  131. # :to_summary => lambda{|w1| return "every" + dayOfWeekChoices[w1][0]},#TODO:see if Time.now can be used to replace this
  132. # :calc_next_date => lambda {|info| return Time.now.next_week.method(info)}#DEBUG: check this
  133. # },
  134. # :m => {#Next day of month: on the 10th day of every month
  135. # :to_summary => lambda{|m1| return "monthly, on day " + m1},
  136. # :calc_next_date => lambda{|info| return Time.now.next_month.change(:day => info.m1)}#TEST needed
  137. # },
  138. # :n => {
  139. # },
  140. # :y => {
  141. # },
  142. # :a => {
  143. # }
  144. # }
  145. end #end repeat_type
  146. #Action.repeatCodeToInfo = function(code, info) {
  147. # info = info || {}; // An info is a hash obj.
  148. # code = code || ''; // A code is a string, like 'm:1:31'.
  149. # var parts = code.split(':');
  150. # info.type = parts[0] || '';
  151. # for (var i = 1; i < parts.length; i++)
  152. # info[info.type + i] = TrimPath.junctionUtil.nanToNull(parseInt(parts[i]));
  153. # return info;
  154. #}
  155. def repeat_code_to_info(code,info)
  156.  
  157. end #end repeat_code_to_info
  158.  
  159. #Action.repeatInfoToCode = function(info) { // TODO: Need validation and error messages.
  160. # var code = null;
  161. # if (info != null &&
  162. # info.type != null &&
  163. # info.type.length > 0) {
  164. # var repeatType = Action.repeatType[info.type];
  165. # if (repeatType != null) {
  166. # var args = [];
  167. # for (var i = 0; i < repeatType.numArgs; i++) {
  168. # var arg = TrimPath.junctionUtil.nanToNull(parseInt(info[info.type + (i + 1)]));
  169. # if (arg != null &&
  170. # arg >= 0)
  171. # args.push(arg);
  172. # }
  173. # if (args.length == repeatType.numArgs)
  174. # code = info.type + ':' + args.join(':');
  175. # }
  176. # }
  177. # return code;
  178. #}
  179. def repeat_info_to_code(info)
  180.  
  181. end #end repeat_info_to_code
  182. #Action.prototype.repeatSummary = function() {
  183. # var result = "";
  184. # if (this.repeat != null &&
  185. # this.repeat.length > 0) {
  186. # var parts = this.repeat.split(':');
  187. # var repeatType = Action.repeatType[parts[0] || ''];
  188. # if (repeatType != null &&
  189. # repeatType.toSummary != null)
  190. # result = repeatType.toSummary.apply(null, parts);
  191. # }
  192. # return result;
  193. #}
  194. def repeat_summary()
  195.  
  196. end #end repeat_summary
  197. #Action.repeatCalcNextDate = function(code, now) {
  198. # if (code != null) {
  199. # var info = Action.repeatCodeToInfo(code);
  200. # if (info != null) {
  201. # var repeatType = Action.repeatType[info.type];
  202. # if (repeatType != null &&
  203. # repeatType.calcNextDate != null)
  204. # return repeatType.calcNextDate(info, now || new Date());
  205. # }
  206. # }
  207. # return null;
  208. #}
  209. def repeat_calc_next_date(code,now)
  210.  
  211. end #end repeat_calc_next_date
  212.  
  213. #Action.prototype.afterUpdate = function() {
  214. # var nowa = new Date();
  215. # var nowb = new Date();
  216. # var nowStr = TrimPath.junctionUtil.toLocalDateString(nowa);
  217. # if (this.repeat != null &&
  218. # this.repeat.length > 0 &&
  219. # this.completedAt != null &&
  220. # TrimPath.junctionUtil.toLocalDateString(this.completedAt) == nowStr) {
  221. # var next = Action.newInstance();
  222. # next.name = this.name;
  223. # next.notes = this.notes;
  224. # next.contextId = this.contextId;
  225. # next.projectId = this.projectId;
  226. # next.color = this.color;
  227. # next.repeat = this.repeat;
  228. #
  229. # // Calculate a repeat period for the activeAt
  230. # if (this.activeAt != null && TrimPath.junctionUtil.toLocalDateString(this.activeAt) > nowStr)
  231. # {
  232. # nowa = new Date(this.activeAt);
  233. # }
  234. # next.activeAt = Action.repeatCalcNextDate(this.repeat, nowa);
  235. # // JGC addition: Calculate a repeat period for the dueAt as well
  236. # if (this.dueAt != null && TrimPath.junctionUtil.toLocalDateString(this.dueAt) > nowStr)
  237. # {
  238. # nowb = new Date(this.dueAt);
  239. # // TODO: Change this.repeat to the actual code that's needed
  240. # }
  241. # var dueRepeat = (this.dueAt - this.activeAt) + next.activeAt;
  242. # next.dueAt = Action.repeatCalcNextDate(dueRepeat, nowb);
  243. # // save the changes
  244. # if ((next.activeAt != null) || (next.dueAt != null))
  245. # next.save();
  246. # }
  247. #}
  248. def after_update()
  249.  
  250. end #end after_update
  251. end
Add Comment
Please, Sign In to add comment