import angular from 'angular';

angular.module('selectedFilesService', []).

service('SelectedFiles', [function() {
  return {
    add: function(file) {
      // Remove any occurrences of this file if they already exist
      this.remove(file.id);
      this.selected.push(file);
    },
    remove: function(uuid) {
      this.selected = this.selected.filter(el => el.id !== uuid);
    },
    list_file_ids: function() {
      var ids = [];
      angular.forEach(this.selected, file => {
        if (file.type === 'file') {
          ids.push(file.id);
        }
      });
      return ids;
    },
    // TODO: look at optimizing file lookup-by-id if this gets used a lot
    get: function(id) {
      for (var i = 0; i < this.selected.length; i++) {
        var item = this.selected[i];
        if (item.id === id) {
          return item;
        }
      }
    },
    selected: [],
  };
}]);

@@ -74,57 +74,368 @@
 ).%0A%0A
-service('SelectedFiles', %5Bfunction() %7B%0A  return %7B
+// Tracks a list of selected files; intended to be used by the Transfer controller%0A// to share the list of files selected in the user interface.%0Aservice('SelectedFiles', %5Bfunction() %7B%0A  return %7B%0A    // Adds a single %60file%60 object to the list of selected files.%0A    // If a file with the same ID already exists in the selection,%0A    // it will be removed first.
 %0A   
@@ -587,24 +587,103 @@
 le);%0A    %7D,%0A
+    // Removes a file with the specified %60id%60 from the list of selected files.%0A
     remove: 
@@ -768,24 +768,88 @@
 id);%0A    %7D,%0A
+    // Lists all of the %60id%60 values for every file in the list.%0A
     list_fil
@@ -1051,16 +1051,176 @@
 ,%0A    //
+ Attempts to locate a file with the given %60id%60 within the file list.%0A    // Returns %60undefined%60 if no matching file is present.%0A    get: function(id) %7B%0A      //
  TODO: l
@@ -1283,32 +1283,8 @@
 lot%0A
-    get: function(id) %7B%0A
     

add API documentation