Class: MetadataController

Inherits:
ApplicationController show all
Defined in:
app/controllers/metadata_controller.rb

Constant Summary

Constants included from ProjectsHelper

ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION

Instance Method Summary collapse

Methods included from RedirectHelper

#destroy_redirect

Methods included from RequestType

#json_request?

Methods included from LogRecent

#log_user_recent_route

Methods included from Cookies

#digest_cookie, #digested_cookie_exists?

Methods included from Whitelist

#whitelist_constantize

Methods included from ProjectsHelper

#cumulative_gb_per_year, #document_cumulative_gb_per_year, #document_gb_per_year, #gb_per_year, #image_cumulative_gb_per_year, #image_gb_per_year, #invalid_object, #project_classification, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #taxonworks_classification, #week_in_review_graphs

Methods included from Api::Intercept

#intercept_api

Methods included from TokenAuthentication

#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate

Instance Method Details

#annotatorsObject

/metadata/annotators.json



34
35
36
# File 'app/controllers/metadata_controller.rb', line 34

def annotators
  render json: helpers.klass_annotations
end

#attributesObject

GET /metadata/attributes?model=CollectingEvent&mode=editable



58
59
60
61
62
63
64
65
# File 'app/controllers/metadata_controller.rb', line 58

def attributes
  render json: Vocabulary.attributes(
    Vocabulary.get_model(
      params.require(:model)
    ), 
    mode: params[:mode]
  )
end

#class_navigationObject



23
24
25
26
# File 'app/controllers/metadata_controller.rb', line 23

def class_navigation
 k = params.require(:klass)
 render json: helpers.class_navigation_json(k)
end

#data_modelsObject



49
50
51
# File 'app/controllers/metadata_controller.rb', line 49

def data_models
  render json: DATA_MODELS.keys.sort
end

#get_klassObject (protected)



69
70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/metadata_controller.rb', line 69

def get_klass
  render json: {status: 400} if (params[:type] && params[:global_id]) || (params[:type].blank? && params[:global_id].blank?)

  if params[:type]
    @klass = params[:type]
    @object = nil
  else
    @object = GlobalID::Locator.locate(params.require(:global_id))
    @klass = OBJECT_RADIALS[@object.class.name] ? @object.class.name : @object.class.base_class.name
  end
end

#indexObject



6
7
8
9
# File 'app/controllers/metadata_controller.rb', line 6

def index
  @klass = params[:klass]
  render '/shared/data/metadata/index'
end

#object_navigationObject



18
19
20
21
# File 'app/controllers/metadata_controller.rb', line 18

def object_navigation
  @object = GlobalID::Locator.locate(params.require(:global_id))
  render json: {status: 200}
end

#object_radialObject

:klass is a base class name, like “Otu”



12
13
14
15
16
# File 'app/controllers/metadata_controller.rb', line 12

def object_radial
  get_klass
  @data = OBJECT_RADIALS[@klass]
  render '/workbench/navigation/object_radial'
end


28
29
30
31
# File 'app/controllers/metadata_controller.rb', line 28

def related_summary
  @klass = params.require(:klass).safe_constantize
  render json: @klass.related_summary(params.require(:id))
end

#vocabularyObject

!! DO NOT EXPOSE TO API !! until santize tested



39
40
41
42
43
44
45
46
47
# File 'app/controllers/metadata_controller.rb', line 39

def vocabulary

  p = params.permit(:model, :attribute, :begins_with, :limit, :contains, :min, :max).merge(project_id: sessions_current_project_id).to_h.symbolize_keys
  if @words = Vocabulary.words(**p)
    render json: @words, status: :ok
  else
    render json: {}, status: :unprocessable_entity
  end
end