Class: AddFiles

Inherits:
Object
  • Object
show all
Defined in:
lib/kuali-sakai-common-lib/add_files.rb

Overview

This class consolidates the code that can be shared among all the File Upload and Attachment pages.

Not every method in this class will be appropriate for every attachment page.

Direct Known Subclasses

AssignmentAttachments, ForumsAddAttachments

Constant Summary collapse

@@classes =
{ :this=>"Superclassdummy", :parent=>"Superclassdummy" }

Instance Method Summary collapse

Instance Method Details

#access_level(filename) ⇒ Object

Gets the value of the access level cell for the specified file.



88
89
90
# File 'lib/kuali-sakai-common-lib/add_files.rb', line 88

def access_level(filename)
  frm.table(:class=>/listHier lines/).row(:text=>/#{Regexp.escape(filename)}/)[6].text
end

#addObject

Clicks the Add button next to the URL field.



82
83
84
# File 'lib/kuali-sakai-common-lib/add_files.rb', line 82

def add
  frm.button(:value=>"Add").click
end

#attach_a_copy(file_name) ⇒ Object

Clicks the “Attach a copy” link for the specified file, then reinstantiates the Class. If an alert box appears, the method will call itself again. Note that this can lead to an infinite loop. Will need to fix later.



156
157
158
159
160
161
162
163
# File 'lib/kuali-sakai-common-lib/add_files.rb', line 156

def attach_a_copy(file_name)
  frm.table(:class=>/listHier lines/).row(:text=>/#{Regexp.escape(file_name)}/).link(:href=>/doAttachitem/).click
  if frm.div(:class=>"alertMessage").exist?
    sleep 1
    attach_a_copy(file_name) # TODO - This can loop infinitely
  end
  instantiate_class(:this)
end

#continueObject

Clicks the Continue button then decides which page class to instantiate based on the page that appears. This is going to need to be fixed.



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/kuali-sakai-common-lib/add_files.rb', line 206

def continue
  frm.div(:class=>"highlightPanel").span(:id=>"submitnotifxxx").wait_while_present
  frm.button(:value=>"Continue").click
  page_title = @browser.div(:class=>"title").text
  case(page_title)
    when "Lessons"
      instantiate_class(:parent)
    when "Assignments"
      if frm.div(:class=>"portletBody").h3.text=~/In progress/ || frm.div(:class=>"portletBody").h3.text == "Select supporting files"
        instantiate_class(:second)
      elsif frm.div(:class=>"portletBody").h3.text=~/edit/i || frm.div(:class=>"portletBody").h3.text=~/add/i
        instantiate_class(:parent)
      elsif frm.form(:id=>"gradeForm").exist?
        instantiate_class(:third)
      end
    when "Forums"
      if frm.div(:class=>"portletBody").h3.text == "Forum Settings"
        instantiate_class(:second)
      else
        instantiate_class(:parent)
      end
    when "Messages"
      if frm.div(:class=>/breadCrumb/).text =~ /Reply to Message/
        instantiate_class(:second)
      else
        instantiate_class(:parent)
      end
    when "Calendar"
      frm.frame(:id, "description___Frame").td(:id, "xEditingArea").frame(:index=>0).wait_until_present
      instantiate_class(:parent)
    when "Portfolio Templates"
      if frm.div(:class=>"portletBody").h3.text=="Select supporting files"
        instantiate_class(:second)
      else
        instantiate_class(:parent)
      end
    else
      instantiate_class(:parent)
  end
end

#create_subfolders_in(folder_name) ⇒ Object

Clicks the Create Folders menu item in the Add menu of the specified folder.



100
101
102
103
104
# File 'lib/kuali-sakai-common-lib/add_files.rb', line 100

def create_subfolders_in(folder_name)
  frm.table(:class=>/listHier lines/).row(:text=>/#{Regexp.escape(folder_name)}/).link(:text=>"Start Add Menu").fire_event("onfocus")
  frm.table(:class=>/listHier lines/).row(:text=>/#{Regexp.escape(folder_name)}/).link(:text=>"Create Folders").click
  instantiate_class(:create_folders)
end

#edit_details(name) ⇒ Object



92
93
94
95
96
# File 'lib/kuali-sakai-common-lib/add_files.rb', line 92

def edit_details(name)
  frm.table(:class=>/listHier lines/).row(:text=>/#{Regexp.escape(name)}/).li(:text=>/Action/, :class=>"menuOpen").fire_event("onclick")
  frm.table(:class=>/listHier lines/).row(:text=>/#{Regexp.escape(name)}/).link(:text=>"Edit Details").click
  instantiate_class(:file_details)
end

#file_namesObject

Returns an array of the file names currently listed on the page.

It excludes folder names.



29
30
31
32
33
34
35
36
37
# File 'lib/kuali-sakai-common-lib/add_files.rb', line 29

def file_names
  names = []
  frm.table(:class=>/listHier lines/).rows.each do |row|
    next if row.td(:class=>"specialLink").exist? == false
    next if row.td(:class=>"specialLink").link(:title=>"Folder").exist?
    names << row.td(:class=>"specialLink").link(:href=>/access.content/, :index=>1).text
  end
  return names
end

#folder_namesObject

Returns an array of the displayed folder names.



15
16
17
18
19
20
21
22
23
# File 'lib/kuali-sakai-common-lib/add_files.rb', line 15

def folder_names
  names = []
  frm.table(:class=>/listHier lines/).rows.each do |row|
    next if row.td(:class=>"specialLink").exist? == false
    next if row.td(:class=>"specialLink").link(:title=>"Folder").exist? == false
    names << row.td(:class=>"specialLink").link(:title=>"Folder").text
  end
  return names
end

#go_to_folder(foldername) ⇒ Object

Clicks on the specified folder name, which should open the folder contents on a refreshed page.



72
73
74
# File 'lib/kuali-sakai-common-lib/add_files.rb', line 72

def go_to_folder(foldername)
  frm.link(:text=>foldername).click
end

#moveObject

Clicks the Move button.



55
56
57
# File 'lib/kuali-sakai-common-lib/add_files.rb', line 55

def move
  frm.button(:value=>"Move").click
end

#open_folder(foldername) ⇒ Object

Clicks on the specified folder image, which will open the folder tree and remain on the page.



66
67
68
# File 'lib/kuali-sakai-common-lib/add_files.rb', line 66

def open_folder(foldername)
  frm.table(:class=>/listHier lines/).row(:text=>/#{Regexp.escape(foldername)}/).link(:title=>"Open this folder").click
end

#removeObject

Clicks the Remove button.



45
46
47
# File 'lib/kuali-sakai-common-lib/add_files.rb', line 45

def remove
  frm.button(:value=>"Remove").click
end

#remove_item(file_name) ⇒ Object

Clicks the remove link for the specified item in the attachment list.



50
51
52
# File 'lib/kuali-sakai-common-lib/add_files.rb', line 50

def remove_item(file_name)
  frm.table(:class=>/listHier/).row(:text=>/#{Regexp.escape(file_name)}/).link(:href=>/doRemoveitem/).click
end

#select_file(filename) ⇒ Object

Clicks the Select button next to the specified file.



40
41
42
# File 'lib/kuali-sakai-common-lib/add_files.rb', line 40

def select_file(filename)
  frm.table(:class=>/listHier lines/).row(:text, /#{Regexp.escape(filename)}/).link(:text=>"Select").click
end

#show_other_sitesObject

Clicks the Show Other Sites link.



60
61
62
# File 'lib/kuali-sakai-common-lib/add_files.rb', line 60

def show_other_sites
  frm.link(:text=>"Show other sites").click
end

#upload_file(filename, filepath = "") ⇒ Object

Enters the specified file into the file field name (assuming it’s in the data/sakai-cle-test-api folder or a subfolder therein)

Does NOT instantiate any class, so use only when no page refresh occurs.



110
111
112
113
114
115
116
# File 'lib/kuali-sakai-common-lib/add_files.rb', line 110

def upload_file(filename, filepath="")
  frm.file_field(:id=>"upload").set(filepath + filename)
  if frm.div(:class=>"alertMessage").exist?
    sleep 2
    upload_file(filename)
  end
end

#upload_file_to_folder(folder_name) ⇒ Object

Clicks the Add Menu for the specified folder, then selects the Upload Files command in the menu that appears.



135
136
137
# File 'lib/kuali-sakai-common-lib/add_files.rb', line 135

def upload_file_to_folder(folder_name)
  upload_files_to_folder(folder_name)
end

#upload_files_to_folder(folder_name) ⇒ Object

Clicks the Add Menu for the specified folder, then selects the Upload Files command in the menu that appears.



142
143
144
145
146
147
148
149
150
# File 'lib/kuali-sakai-common-lib/add_files.rb', line 142

def upload_files_to_folder(folder_name)
  if frm.li(:text=>/A/, :class=>"menuOpen").exist?
    frm.table(:class=>/listHier lines/).row(:text=>/#{Regexp.escape(folder_name)}/).li(:text=>/A/, :class=>"menuOpen").fire_event("onclick")
  else
    frm.table(:class=>/listHier lines/).row(:text=>/#{Regexp.escape(folder_name)}/).link(:text=>"Start Add Menu").fire_event("onfocus")
  end
  frm.table(:class=>/listHier lines/).row(:text=>/#{Regexp.escape(folder_name)}/).link(:text=>"Upload Files").click
  instantiate_class(:upload_files)
end

#upload_local_file(filename, filepath = "") ⇒ Object

Enters the specified file into the file field name (assuming it’s in the data/sakai-cle-test-api folder or a subfolder therein)

Use this method ONLY for instances where there’s a file field on the page with an “upload” id.



123
124
125
126
127
128
129
130
# File 'lib/kuali-sakai-common-lib/add_files.rb', line 123

def upload_local_file(filename, filepath="")
  frm.file_field(:id=>"upload").set(filepath + filename)
  if frm.div(:class=>"alertMessage").exist?
    sleep 2
    upload_local_file(filename)
  end
  instantiate_class(:this)
end

#upload_multiple_files_to_folder(folder, file_array, file_path = "") ⇒ Object

Takes the specified array object containing pointers to local file resources, then uploads those files to the folder specified, checks if they all uploaded properly and if not, re-tries the ones that failed the first time.

Finally, it re-instantiates the appropriate page class. Note that it expects all files to be located in the same folder (can be in subfolders of that folder).



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/kuali-sakai-common-lib/add_files.rb', line 180

def upload_multiple_files_to_folder(folder, file_array, file_path="")

  upload = upload_files_to_folder folder

  file_array.each do |file|
    upload.file_to_upload(file, file_path)
    upload.add_another_file
  end

  resources = upload.upload_files_now

  file_array.each do |file|
    file =~ /(?<=\/).+/
    # puts $~.to_s # For debugging purposes
    unless resources.file_names.include?($~.to_s)
      upload_files = resources.upload_files_to_folder(folder)
      upload_files.file_to_upload(file, file_path)
      resources = upload_files.upload_files_now
    end
  end
  instantiate_class(:this)
end

#url=(url_string) ⇒ Object

Sets the URL field to the specified value.



77
78
79
# File 'lib/kuali-sakai-common-lib/add_files.rb', line 77

def url=(url_string)
  frm.text_field(:id=>"url").set(url_string)
end

#what_is_parent?Boolean

Use this for debugging purposes only…

Returns:

  • (Boolean)


10
11
12
# File 'lib/kuali-sakai-common-lib/add_files.rb', line 10

def what_is_parent?
  puts @@classes[:parent]
end