Developer Cheatsheet - UVicLibrary/Vault GitHub Wiki
Quick Links
Command Line
- Restart the server (i.e. Apache)
- Change the permissions or ownership of a file or folder (recursively)
- Search recursively for a string (of text) in a directory or file
Navigating the Rails Console
- Start the rails console for vault.library.uvic.ca
- Clear the rails console
- Search for a string within a list of an object's methods
Find [. . .] , given a [. . . ]
- Find the corresponding solr document, given a collection, work, or file set
- Find all works in a collection, given that collection's ID
Create a Sample or Test Object
- collection presenter with admin privileges
- work show presenter with admin privileges
- file set presenter with admin privileges
Working with Metadata
- List IIIF metadata fields (which appear in the IIIF manifest)
- List controlled vocabulary fields (also called authority fields)
- List required fields
- List primary terms (fields above the fold)
- List secondary terms ("additional fields" below the fold)
- List all terms
The Solr Admin Panel
- Finding a document by ID
- Common query parameters
- Limiting results by model (collection, work, file set)
- Updating or posting information
- Return all index entries where a field is blank
- Return all index entries where a field is NOT blank
Miscellaneous
- Change the visibility of a work, collection, or file set
- Link_to tag with route helpers
- Reindex an item
- Return the current host/tenant
General Navigation (Command Line)
Start the rails console for vault.library.uvic.ca
- login and cd into
home/sufia/vault
rails c -e production
AccountElevator.switch! "vault.library.uvic.ca"
Restart the server (i.e. Apache)
sudo systemctl restart httpd
- pushes changes into production
- remember to also exit and restart the rails console!
- if a job is running, remember to restart sidekiq too
Change the permissions or ownership of a file or folder (recursively)
- Change ownership:
sudo chown [username] [file name or path] -R
- Change group writing permissions (when logged in as the eponymous user of a group):
sudo chmod g+w [file name or path] -R
- See who a group's members are:
groups [group name]
or justgroups
to see members of current user's group
Clear the rails console
- Press
cntrl + l
Search recursively for a string (of text) in a directory or file
- recursive = search that directory and all the directories and files it contains
- searches file names as well as the text within those files
grep -rnw path/to/dir -e "search text"
Search for a string within a list of an object's methods
- For when you think there's already a method that returns what you want, but you don't remember what it's called
GenericWork.methods.grep(/string/)
Find [. . .] , given a [. . . ]
Find the corresponding solr document, given a collection, work, or file set
- where object is the Collection, GenericWork, or FileSet object:
SolrDocument.find(object.id)
Find all works in a collection, given that collection's ID
GenericWork.where(member_of_collection_ids_ssim: collection_id)
Find an array of all collection IDs that a work is in, given that work
GenericWork.member_of_collection_ids
Create a Sample or Test Object
Every collection/work/file set presenter needs two parameters:
- a
solr_document
, which you can find like this - a current_ability (we'll set this to admin)
Collection presenter with admin privileges
Hyrax::CollectionPresenter.new(solr_document, "admin")
Work show presenter with admin privileges
Hyrax::WorkShowPresenter.new(solr_document, "admin")
File set presenter with admin privileges
Hyrax::FileSetPresenter.new(solr_document, "admin")
Working with Metadata
List IIIF metadata fields
Hyrax.config.iiif_metadata_fields
- This is defined in
lib/hyrax/configuration.rb
List controlled vocabulary fields
fs = FileSet.last # Pick a specific file set or generic work
FileSet.controlled_properties
=> [:creator, :contributor, etc.]
List required fields
- For a generic work:
Hyrax::GenericWorkForm.required_fields
- For a file set:
Hyrax::FileSetForm.required_fields
- See hyrax list of notable methods
List primary terms
- For a generic work:
Hyrax::GenericWorkForm.primary_terms
- For a file set:
Hyrax::FileSetForm.primary_terms
- See hyrax list of notable methods
List secondary terms
- For a generic work:
Hyrax::GenericWorkForm.secondary_terms
- For a file set:
Hyrax::FileSetForm.secondary_terms
- See hyrax list of notable methods
List all terms
- For a generic work:
Hyrax::GenericWorkForm.terms
- For a file set:
Hyrax::FileSetForm.terms
- See hyrax list of notable methods
The Solr Admin Panel
Finding a document by ID
- Navigate to a show page for a work or file set
- Copy its ID from the URL
- Go to the Query page in the Solr dashboard
- In
fq
, typeid:
and then paste in the item ID - Click Query
Common query parameters
Limiting results by model
- Go to the Query page in the Solr dashboard
- In
fq
, typehas_model_ssim:
and then the model name (e.g.GenericWork
,FileSet
) - Click Query
Updating or posting information
Return all index entries where a field is blank
- Example: a field called
year_tesim
- In the
fq
box:-year_tesim:["" TO *]
Return all index entries where a field is NOT blank
- Example: a field called
year_tesim
- In the
fq
box:-year_tesim:[* TO *]
Miscellaneous
Change visibility of a collection, work, or file set
- See instructions on how to do this through the interface
- For a generic work, for example:
gw = GenericWork.last
gw.visibility = "open"
gw.save
- To make a work private, you would do
gw.visibility = "restricted"
andgw.save
Link_to tag with route helpers
- If you are using a helper path that is outside the hyrax namespace (e.g.
toggle_downloads_path
), you will have to format thelink_to
tag like this:
<%= link_to "link text", main_app.toggle_downloads_path(local_variable: value...), remote: true, method: post, class: "some-class" %>
- See
views/hyrax/dashboard/collections/_form_discovery.html.erb
as an example
Reindex an item
gw.update_index
(same for collections and file sets)
Return the current host/tenant
request.base_url
(for views) orAccount.find_by(tenant: Apartment::Tenant.current).&cname
(whererequest.base_url
doesn't work)- As a true/false statement to check which tenant:
request.base_url.include? "vault"
orAccount.find_by(tenant: Apartment::Tenant.current).&cname.include? "vault"