Class: Neoneo::Project
- Inherits:
-
Object
- Object
- Neoneo::Project
- Defined in:
- lib/neoneo.rb
Overview
Representation of No Kahuna’s projects.
It holds all information about a project, like it’s name and description, it’s categories, members and tasks. It’s also used to add new tasks to a project and can also be used to change the name and description of the project.
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#description ⇒ Object
Returns the value of attribute description.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#own_tasks ⇒ Object
Returns the value of attribute own_tasks.
-
#total_tasks ⇒ Object
Returns the value of attribute total_tasks.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#add_task(description, options = {}) ⇒ Object
Adds a task to a project.
- #categories ⇒ Object
-
#closed_tasks ⇒ Object
The closed tasks of the project.
-
#initialize(id, name, total_tasks, own_tasks, user) ⇒ Project
constructor
A new instance of Project.
- #members ⇒ Object
-
#save ⇒ Object
Saves the project name and descriptions which you can set simply with name= and description= An example: project = Neoneo::User.new(‘John Doe’, ‘god’).projects.find(‘My Project’) project.name = ‘BLA!’ project.description = ‘New description’ project.save.
-
#tasks ⇒ Object
The open tasks of the project.
-
#url(appendix = '') ⇒ Object
The URL to the project at No Kahuna.
Constructor Details
#initialize(id, name, total_tasks, own_tasks, user) ⇒ Project
Returns a new instance of Project.
177 178 179 180 181 182 183 184 |
# File 'lib/neoneo.rb', line 177 def initialize(id, name, total_tasks, own_tasks, user) @id = id @name = name @total_tasks_count = total_tasks @own_tasks_count = own_tasks @user = user end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
174 175 176 |
# File 'lib/neoneo.rb', line 174 def agent @agent end |
#description ⇒ Object
Returns the value of attribute description.
175 176 177 |
# File 'lib/neoneo.rb', line 175 def description @description end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
174 175 176 |
# File 'lib/neoneo.rb', line 174 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
175 176 177 |
# File 'lib/neoneo.rb', line 175 def name @name end |
#own_tasks ⇒ Object
Returns the value of attribute own_tasks.
175 176 177 |
# File 'lib/neoneo.rb', line 175 def own_tasks @own_tasks end |
#total_tasks ⇒ Object
Returns the value of attribute total_tasks.
175 176 177 |
# File 'lib/neoneo.rb', line 175 def total_tasks @total_tasks end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
174 175 176 |
# File 'lib/neoneo.rb', line 174 def user @user end |
Instance Method Details
#add_task(description, options = {}) ⇒ Object
Adds a task to a project. The options hash can consist of the following keys:
- :category => 'Some Category Name' OR some_category_object
- :assign_to => 'Some User Name' OR some_member_object
- :notify => 'Some User Name' OR some_member_object OR an array of them
An example:
project = Neoneo::User.new('John Doe', 'god').projects.find('My Project')
project.add_task("A shiny new task",
:assign_to => 'Bob Dillan',
:category => project.categories.first,
:notify => ['John Doe', project.members.last])
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/neoneo.rb', line 256 def add_task(description, = {}) page = user.agent.get(url('tasks/new')) build_categories!(page) unless @categories build_members!(page) unless @members category = categories.find_or_use([:category]) assign_to = members.find_or_use([:assign_to]) notifications = Array.new case [:notify] when Array [:notify].each do |member| notifications << members.find_or_use(member) end else notifications << members.find_or_use([:notify]) end notifications.compact! page = user.agent.get(url('tasks/new')) form = page.forms.last form.send('task[body]'.to_sym, description) form.send('task[assigned_to_id]'.to_sym, assign_to.id) if assign_to form.send('task[category_id]'.to_sym, category.id) if category notifications.each do |notification| form.add_field!('subscriber_ids[]', notification.id) end user.agent.submit form end |
#categories ⇒ Object
198 199 200 201 202 |
# File 'lib/neoneo.rb', line 198 def categories build_categories!(user.agent.get(url('tasks/new'))) unless @categories @categories end |
#closed_tasks ⇒ Object
The closed tasks of the project
For technical reasons I decided to devide the tasks into closed and open ones hoping that nobody really needs the closed ones ;) The problem is: At the moment the only chance to get an overview of closed tasks in the No Kahuna interface is to search for ‘task’. But then you get no category information with the tasks. So I decided that it is more important to have the category information for any task available without the need to load a single page for any task which is possible with the normal task overview and which the tasks method does. If you really would like to see the closed tasks use this method by be aware, that if you access the category of a closed task a new HTTP request has to made!
Also watch out for an other pitfall: If you close or reopen a task they stay in their original array! So if you do
project.tasks.first.close!
a call to
project.tasks
just after that would INCLUDE the closed task and if you already had called closed_tasks another call to that would NOT INCLUDE the closed task!
239 240 241 242 243 |
# File 'lib/neoneo.rb', line 239 def closed_tasks build_closed_tasks!(user.agent.get(url('tasks/search?s=task'))) unless @closed_tasks @closed_tasks end |
#members ⇒ Object
204 205 206 207 208 |
# File 'lib/neoneo.rb', line 204 def members build_members!(user.agent.get(url('tasks/new'))) unless @members @members end |
#save ⇒ Object
Saves the project name and descriptions which you can set simply with name= and description= An example:
project = Neoneo::User.new('John Doe', 'god').projects.find('My Project')
project.name = 'BLA!'
project.description = 'New description'
project.save
297 298 299 300 301 302 303 304 305 306 |
# File 'lib/neoneo.rb', line 297 def save page = user.agent.get(url('edit')) form = page.forms.last form.send('project[name]='.to_sym, @name) form.send('project[description]='.to_sym, @description) if @description page = user.agent.submit form raise Error unless page.search('div#flash.notice p').first.clean == 'Successfully saved project' end |
#tasks ⇒ Object
The open tasks of the project
211 212 213 214 215 |
# File 'lib/neoneo.rb', line 211 def tasks build_tasks!(user.agent.get(url('tasks?group_by=category'))) unless @tasks @tasks end |
#url(appendix = '') ⇒ Object
The URL to the project at No Kahuna
309 310 311 |
# File 'lib/neoneo.rb', line 309 def url(appendix = '') "#{PROJECT_URL}#{@id}/#{appendix}" end |