Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
474 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class ImportController < ApplicationController | ||
|
||
require_role [ :admin ] | ||
|
||
def create | ||
action = params[:commit] | ||
|
||
case action | ||
when "Edit" | ||
redirect_to edit_import_map_path( params[:map] ) | ||
when "New"; | ||
redirect_to new_import_map_path | ||
when "import"; | ||
else render_nothing | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
class ImportMapsController < ApplicationController | ||
|
||
def yml | ||
@import_map = ImportMap.find(params[:id]) | ||
end | ||
|
||
def new | ||
@verb = "New" | ||
@import_map = ImportMap.new | ||
render "form" | ||
end | ||
|
||
def edit | ||
@verb = "Edit" | ||
@import_map = ImportMap.find(params[:id]) | ||
@yml = YAML::load( @import_map.yml ) | ||
render "form" | ||
end | ||
|
||
# POST /import_maps | ||
# POST /import_maps.xml | ||
def _create | ||
@import_map = ImportMap.new(params[:import_map]) | ||
|
||
respond_to do |format| | ||
if @import_map.save | ||
flash[:notice] = 'ImportMap was successfully created.' | ||
format.html { redirect_to(@import_map) } | ||
format.xml { render :xml => @import_map, :status => :created, :location => @import_map } | ||
else | ||
format.html { render :action => "new" } | ||
format.xml { render :xml => @import_map.errors, :status => :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
def update | ||
@import_map = ImportMap.find(params[:id]) | ||
if @import_map.update_attributes(params[:import_map]) | ||
flash[:notice] = 'ImportMap was successfully updated.' | ||
redirect_to edit_import_map_path @import_map | ||
else | ||
if params[:import_map][:yml] | ||
render :action => "yml" | ||
else | ||
raise "hell" | ||
render :action => "edit" | ||
end | ||
end | ||
end | ||
|
||
# DELETE /import_maps/1 | ||
# DELETE /import_maps/1.xml | ||
def _destroy | ||
@import_map = ImportMap.find(params[:id]) | ||
@import_map.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to(import_maps_url) } | ||
format.xml { head :ok } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module ImportHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module ImportMapsHelper | ||
|
||
def fields | ||
@fields ||= begin | ||
[ "not mapped" ] + | ||
(( %w(title sentence abstract duration local_id donor | ||
alternative_title series_title audience classification | ||
language_note creation_credits participation_credits | ||
preservation_note transcript notes public tags Asset) + | ||
PropertyType.find(:all).to_a.map(&:name) ). | ||
sort {|a,b| a.downcase <=> b.downcase || a <=> b }) | ||
|
||
end | ||
end | ||
|
||
def primary value | ||
case value | ||
when Hash; value = value.keys[0] | ||
end | ||
value | ||
end | ||
|
||
def secondary value | ||
case value | ||
when Hash; value.values[0] | ||
else; nil | ||
end | ||
end | ||
|
||
def field_options | ||
fields.map do |field| | ||
[ field, field ] | ||
end | ||
end | ||
|
||
def tertiary value | ||
set = PropertyType.find_by_name value | ||
if set | ||
set.values.map(&:to_s).sort {|a,b| a.downcase <=> b.downcase || a <=> b } | ||
else | ||
raise "#{value.inspect}" | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class ImportMap < ActiveRecord::Base | ||
|
||
validate do |map| | ||
begin | ||
YAML.load StringIO.new( map.yml ) | ||
rescue Exception => e | ||
map.errors.add :yml, e.message | ||
end | ||
end | ||
|
||
end |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
- form_tag( { :action => "create" }, { :multipart => true } ) do | ||
|
||
%fieldset.import | ||
%legend Import Videos | ||
|
||
%div | ||
%label | ||
Select Import Map: | ||
%select{:name => "map"} | ||
= options_for_select | | ||
( ImportMap.find(:all).to_a.map { |im| [ im.name, im.id ] } ) | | ||
= submit_tag "Edit" | ||
= submit_tag "New" | ||
|
||
%br | ||
|
||
%div | ||
%label | ||
Select CSV File: | ||
= file_field_tag "csv" | ||
|
||
%br | ||
|
||
%div | ||
= submit_tag "import" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
- ( key, value, set ) = map_entry | ||
- set ||= field_options | ||
%div | ||
%label | ||
%span.key{:style=>"display:inline-block;width:10em;"} | ||
= "#{key}: " | ||
%span.value | ||
%select{:name => key} | ||
= options_for_select set, primary(value) | ||
/ = debug( secondary(value) ) | ||
- if sec = secondary(value) and | | ||
primary(value) != "tags" and | | ||
primary(value) != "public" | | ||
%div{:style=>"margin-left: 2em"} | ||
- keys = sec.keys.sort {|a,b| a.downcase <=> b.downcase || a <=> b } | ||
- keys.each do |k| | ||
- v = sec[k] | ||
= render :partial => "map_entry", | | ||
:object => [k, v, tertiary(primary(value) ) ] | | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
%fieldset.import_map | ||
|
||
%legend | ||
= @verb | ||
Import Map | ||
|
||
- form_for template_import_map_path( @import_map ), | | ||
{ :multipart => true } do | | ||
- | ||
%div{:style=>"text-align:center;width:100%"} | ||
%div | ||
%label | ||
Upload template CSV File: | ||
= file_field_tag "csv" | ||
= submit_tag "upload" | ||
|
||
%br | ||
|
||
%hr{:style=>'width:75%;margin:0 auto 0 auto'} | ||
|
||
%br | ||
|
||
= link_to "Edit YAML", yml_import_map_path( @import_map ) | ||
|
||
%br | ||
%br | ||
|
||
%hr{:style=>'width:75%;margin:0 auto 0 auto'} | ||
|
||
%br | ||
|
||
- form_for @import_map, { :multipart => true } do | ||
|
||
%div{:style => "margin-left: 5em;"} | ||
- keys = @yml.keys.sort {|a,b| a.downcase <=> b.downcase || a <=> b } | ||
- keys.each do |k| | ||
- v = @yml[k] | ||
= render :partial => "map_entry", :object => [k, v, nil] | ||
|
||
%div | ||
= submit_tag "save" | ||
= link_to "cancel", import_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
- if !(errors = error_message_on @import_map, :yml).blank? | ||
%div.flash.errors{:style=>"color:red"} | ||
= errors | ||
|
||
- form_for @import_map do |form| | ||
|
||
%div{:style=>"width:100%;text-align:center;"} | ||
= form.text_area :yml, :rows => 50, | | ||
:style=>"width:80%;font-size:2em;" | | ||
|
||
%br | ||
%br | ||
|
||
= form.submit "Save" | ||
= link_to "Cancel", edit_import_map_path( @import_map ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class CreateImportMaps < ActiveRecord::Migration | ||
def self.up | ||
create_table :import_maps do |t| | ||
t.string :name, :null => false | ||
t.text :yml, :null => false | ||
t.timestamps | ||
end | ||
|
||
add_index :import_maps, :name, :unique => true | ||
end | ||
|
||
def self.down | ||
drop_table :import_maps | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'yaml' | ||
|
||
File.open( "openvideo_source_10-21-2008_vid-Table 1.map" ) do |f| | ||
yml = f.read | ||
hash = { "open_video" => { "name" => "Open Video Test Map", | ||
"yml" => yml } } | ||
|
||
File.open( "fixture.yml", "w" ) do |w| | ||
YAML::dump hash, w | ||
end | ||
end |
65 changes: 65 additions & 0 deletions
65
doc/import/samples/openvideo_source_10-21-2008/fixture.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
open_video: | ||
name: Open Video Test Map | ||
yml: | | ||
videoid: local_id | ||
asset: Asset | ||
locationurl: nil | ||
title: title | ||
description: abstract | ||
digitizationdate: Digitization | ||
amtMotion: nil | ||
transcriptText: nil | ||
statsText: nil | ||
numberOfFrames: nil | ||
verified?: | ||
public: | ||
"Yes": true | ||
"No": false | ||
timestamp: nil | ||
keywords: | ||
tags: Tag | ||
posterframe: nil | ||
duration: duration | ||
restricted?: nil | ||
creationdate: Creation | ||
framerate: nil | ||
sound: | ||
Sound: | ||
"Yes": Sound | ||
"No": Silent | ||
color: | ||
Color: | ||
"Yes": Color | ||
"No": Black and White | ||
edited?: nil | ||
segmentation: nil | ||
sponsorname: nil | ||
contribOrgID: nil | ||
languageid: | ||
Language: | ||
"1": English | ||
frameDimensionID: nil | ||
digitizOrgID: nil | ||
genrePrimaryID: | ||
Genre: | ||
"1": Documentary | ||
"2": Corporate | ||
"3": Historical | ||
"4": Ephemeral | ||
"5": Lecture | ||
genreSecondaryID: | ||
Genre: | ||
"1": Documentary | ||
"2": Corporate | ||
"3": Historical | ||
"4": Ephemeral | ||
"5": Lecture | ||
RightsInformationID: | ||
Rights Statement: | ||
"1": All Rights Reserved | ||
# Local Variables: | ||
# mode:yaml | ||
# End: | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | ||
|
||
describe ImportController do | ||
|
||
#Delete this example and add some real ones | ||
it "should use ImportController" do | ||
controller.should be_an_instance_of(ImportController) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | ||
|
||
describe ImportMapsController do | ||
end |
Oops, something went wrong.