Giter Site home page Giter Site logo

hydra-editor's Introduction

HydraEditor

Code: Gem Version Build Status Coverage Status

Docs: Contribution Guidelines Apache 2.0 License

Jump in: Slack Status

What is hydra-editor?

A basic metadata editor for Rails applications based on hydra-head.

Product Owner & Maintenance

hydra-editor is a Core Component of the Samvera community. The documentation for what this means can be found here.

Product Owner

jrgriffiniii

Help

The Samvera community is here to help. Please see our support guide.

Getting Started

To use add to your gemfile:

gem 'hydra-editor'

Then run:

bundle install

Next generate the bootstrap form layouts:

rails generate simple_form:install --bootstrap

And to config/routes.rb add:

  mount HydraEditor::Engine => '/'

(Note: You do not have to mount the engine if you do not intend to use the engine's default routes.)

In your initialization set HydraEditor.models

# config/initializers/hydra_editor.rb
HydraEditor.models = ["RecordedAudio", "PdfModel"]

You can customize the names of your fields/models by adding to your translation file:

# config/locales/en.yml
en:
  hydra_editor:
    form:
      model_label:
        PdfModel: "PDF"
        RecordedAudio: "audio"

  simple_form:
    labels:
      image:
        dateCreated: "Date Created"
        sub_location: "Holding Sub-location"

Create a form object for each of your models.

# app/forms/recorded_audio_form.rb
class RecordedAudioForm
  include HydraEditor::Form
  self.model_class = RecordedAudio
  self.terms = [] # Terms to be edited
  self.required_fields = [] # Required fields
end

Add the javascript by adding this line to your app/assets/javascript/application.js:

//= require hydra-editor/hydra-editor

Add the stylesheets by adding this line to your app/assets/stylesheets/application.css:

 *= require hydra-editor/hydra-editor

(Note: The Javascript includes require Blacklight and must be put after that.)

Updating to 4.0.0

  • SimpleForm is supported from release 3.2.0 onwards
  • #to_model now returns self (previously it was the value of @model):
      class MyForm
        include HydraEditor::Form
        self.model_class = MyModel
        self.terms = [:title, :creator]
        # [...]
      end
      # [...]
      some_work = MyModel.new(title: ['Black holes: The Reith Lectures.'], creator: 'S.W. Hawking')
      some_form = MyForm.new(some_work)
      # [...]
      some_form.to_model
      # => #<MyForm:0x00007fd5b2fd1468 @attributes={"id"=>nil, "title"=>["Black holes: The Reith Lectures."], "creator"=>"S.W. Hawking"}, @model=#<MyModel id: nil, title: ["Black holes: The Reith Lectures."], creator: "S.W. Hawking">>
  • When a form field for a single value is empty, it now returns a nil value (as opposed to an empty String):
      class MyForm
        include HydraEditor::Form
        self.model_class = MyModel
        self.terms = [:title, :creator]
        # [...]
      end
    
      # [...]
      values = MyForm.model_attributes(
        title: ['On the distribution of values of angles determined by coplanar points.'],
        creator: ''
      )
      values['creator']
      # => nil

Other customizations

By default hydra-editor provides a RecordsController with :new, :create, :edit, and :update actions implemented in the included RecordsControllerBehavior module, and a RecordsHelper module with methods implemented in RecordsHelperBehavior. If you are mounting the engine and using its routes, you can override the controller behaviors by creating your own RecordsController:

class RecordsController < ApplicationController
  include RecordsControllerBehavior

  # You custom code
end

If you are not mounting the engine or using its default routes, you can include RecordsControllerBehavior in your own controller and add the appropriate routes to your app's config/routes.rb.

Acknowledgments

This software has been developed by and is brought to you by the Samvera community. Learn more at the Samvera website.

Samvera Logo

hydra-editor's People

Contributors

jcoyne avatar mjgiarlo avatar jrgriffiniii avatar dchandekstark avatar awead avatar atz avatar jeremyf avatar jechols avatar flyingzumwalt avatar cjcolvar avatar botimer avatar cbeer avatar tpendragon avatar carolyncole avatar hectorcorrea avatar mkorcy avatar afred avatar hackartisan avatar barmintor avatar grosscol avatar val99erie avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.