Class: Graphql::Dashboard::OperationStore::OperationsController

Inherits:
BaseController show all
Defined in:
lib/graphql/dashboard/operation_store.rb

Instance Method Summary collapse

Methods included from Installable

#check_installed, #feature_installed?, included

Methods inherited from ApplicationController

#schema_class

Instance Method Details

#index ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/graphql/dashboard/operation_store.rb', line 84

def index
  @client_operations = client_name = params[:client_name]
  per_page = params[:per_page]&.to_i || 25
  page = params[:page]&.to_i || 1
  @is_archived = params[:archived_status] == :archived
  order_by = params[:order_by] || "name"
  order_dir = params[:order_dir]&.to_sym || :asc
  if @client_operations
    @operations_page = schema_class.operation_store.get_client_operations_by_client(
      client_name,
      page: page,
      per_page: per_page,
      is_archived: @is_archived,
      order_by: order_by,
      order_dir: order_dir,
    )
    opposite_archive_mode_count = schema_class.operation_store.get_client_operations_by_client(
      client_name,
      page: 1,
      per_page: 1,
      is_archived: !@is_archived,
      order_by: order_by,
      order_dir: order_dir,
    ).total_count
  else
    @operations_page = schema_class.operation_store.all_operations(
      page: page,
      per_page: per_page,
      is_archived: @is_archived,
      order_by: order_by,
      order_dir: order_dir,
    )
    opposite_archive_mode_count = schema_class.operation_store.all_operations(
      page: 1,
      per_page: 1,
      is_archived: !@is_archived,
      order_by: order_by,
      order_dir: order_dir,
    ).total_count
  end

  if @is_archived
    @archived_operations_count = @operations_page.total_count
    @unarchived_operations_count = opposite_archive_mode_count
  else
    @archived_operations_count = opposite_archive_mode_count
    @unarchived_operations_count = @operations_page.total_count
  end
end

#show ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/graphql/dashboard/operation_store.rb', line 134

def show
  digest = params[:digest]
  @operation = schema_class.operation_store.get_operation_by_digest(digest)
  if @operation
    # Parse & re-format the query
    document = GraphQL.parse(@operation.body)
    @graphql_source = document.to_query_string

    @client_operations = schema_class.operation_store.get_client_operations_by_digest(digest)
    @entries = schema_class.operation_store.get_index_entries_by_digest(digest)
  end
end

#update ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/graphql/dashboard/operation_store.rb', line 147

def update
  is_archived = case params[:modification]
  when :archive
    true
  when :unarchive
    false
  else
    raise ArgumentError, "Unexpected modification: #{params[:modification].inspect}"
  end

  if (client_name = params[:client_name])
    operation_aliases = params[:operation_aliases]
    schema_class.operation_store.archive_client_operations(
      client_name: client_name,
      operation_aliases: operation_aliases,
      is_archived: is_archived
    )
    flash[:success] = "#{is_archived ? "Archived" : "Activated"} #{operation_aliases.size} #{"operation".pluralize(operation_aliases.size)}"
  else
    digests = params[:digests]
    schema_class.operation_store.archive_operations(
      digests: digests,
      is_archived: is_archived
    )
    flash[:success] = "#{is_archived ? "Archived" : "Activated"} #{digests.size} #{"operation".pluralize(digests.size)}"
  end
  head :no_content
end