Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin frontend #38

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3426726
Created initial table for admin list
nwalker2398 Jan 29, 2024
328e669
Added boostrap to repo
nwalker2398 Jan 29, 2024
2a475e6
Added styled-components
nwalker2398 Jan 29, 2024
9ee020c
Added search bar component
nwalker2398 Jan 29, 2024
1954e1a
Implemented list filtering by status and searching by identifier
nwalker2398 Jan 30, 2024
90b9a7e
Added dynamic filter choices
nwalker2398 Jan 30, 2024
f272e67
Added pagination and navigation buttons
nwalker2398 Jan 30, 2024
1d1c0b1
Style fixes and test debugging
nwalker2398 Jan 31, 2024
25ce092
Moved resource list to using react-router
nwalker2398 Feb 7, 2024
2c7d0a9
Implemented url updates for search parameters
nwalker2398 Feb 12, 2024
d9ad588
Added amin user priveledge requirement to resource list route
nwalker2398 Feb 12, 2024
5c94e36
Deployment fix
nwalker2398 Feb 12, 2024
a1d270f
More deployment fixes
nwalker2398 Feb 13, 2024
9ead87a
Reverting deployment fixes
nwalker2398 Feb 13, 2024
d385c87
Removed package-lock.json
nwalker2398 Feb 13, 2024
231c90d
Updated to dynamically request resources one page at a time
nwalker2398 Feb 13, 2024
b6fc140
Added 'created_at' and 'updated_at' columns
nwalker2398 Feb 13, 2024
27e1647
Updated status URL parsing to work with strings
nwalker2398 Feb 14, 2024
3e42bfb
Fixed issue with status and PCDM type not being passed to the frontend
nwalker2398 Feb 14, 2024
8cf5c1a
Finished implementing strong parameters
nwalker2398 Feb 16, 2024
d296564
Added tests for identifier and status filtering
nwalker2398 Feb 16, 2024
3c5a1e6
added a per_page field to the URL parameters, added page test
nwalker2398 Feb 16, 2024
2043250
fixed error with going past the final page
nwalker2398 Feb 16, 2024
38d5771
style fixes
nwalker2398 Feb 16, 2024
8a00138
Added per-page field to search bar
nwalker2398 Feb 16, 2024
20fdc62
Fixed an issue with clearing search terms
nwalker2398 Feb 16, 2024
2d7bf72
More style fixes
nwalker2398 Feb 19, 2024
ebccb97
fixed a bug with not handling null fields properly
nwalker2398 Feb 19, 2024
4b2afb0
Fixed an issue with identifier null values
nwalker2398 Feb 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 9 additions & 68 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# This configuration was generated by
# `rubocop --auto-gen-config --exclude-limit 10000`
# on 2024-01-09 21:03:14 UTC using RuboCop version 1.59.0.
# on 2024-02-16 22:15:49 UTC using RuboCop version 1.59.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 6
# Offense count: 7
# This cop supports safe autocorrection (--autocorrect).
Layout/EmptyLineAfterGuardClause:
Exclude:
- 'app/controllers/api_controller.rb'
- 'app/models/resource.rb'
- 'lib/triclops/raster.rb'

# Offense count: 6
# Offense count: 7
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: normal, indented_internal_methods
Expand All @@ -24,7 +24,7 @@ Layout/IndentationConsistency:
- 'app/controllers/api_controller.rb'
- 'app/controllers/application_controller.rb'

# Offense count: 6
# Offense count: 7
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Width, AllowedPatterns.
Layout/IndentationWidth:
Expand All @@ -33,22 +33,10 @@ Layout/IndentationWidth:
- 'app/controllers/api_controller.rb'
- 'app/controllers/application_controller.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Layout/SpaceAfterComma:
Exclude:
- 'app/models/user.rb'

# Offense count: 1
# Configuration parameters: AllowKeywordBlockArguments.
Lint/UnderscorePrefixedVariableName:
Exclude:
- 'app/models/user.rb'

# Offense count: 1
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 32
Max: 43

# Offense count: 1
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
Expand All @@ -59,27 +47,12 @@ Metrics/BlockLength:
# Offense count: 1
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Max: 8

# Offense count: 1
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 19
Max: 12

# Offense count: 1
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/PerceivedComplexity:
Max: 9

# Offense count: 1
# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
# NamePrefix: is_, has_, have_
# ForbiddenPrefixes: is_, has_, have_
# AllowedMethods: is_a?
# MethodDefinitionMacros: define_method, define_singleton_method
Naming/PredicateName:
Exclude:
- 'app/models/user.rb'
Max: 12

# Offense count: 21
# This cop supports safe autocorrection (--autocorrect).
Expand Down Expand Up @@ -159,21 +132,6 @@ Rails/IndexWith:
Exclude:
- 'app/models/concerns/triclops/resource/as_json.rb'

# Offense count: 1
# Configuration parameters: Include.
# Include: app/models/**/*.rb
Rails/UniqueValidationWithoutIndex:
Exclude:
- 'app/models/user.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, conditionals
Style/AndOr:
Exclude:
- 'app/models/user.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Keywords, RequireColon.
Expand All @@ -182,14 +140,6 @@ Style/CommentAnnotation:
Exclude:
- 'spec/requests/iiif/images/raster_spec.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions.
# SupportedStyles: assign_to_condition, assign_inside_condition
Style/ConditionalAssignment:
Exclude:
- 'app/models/user.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Style/ExpandPathArguments:
Expand All @@ -202,14 +152,6 @@ Style/ExplicitBlockArgument:
Exclude:
- 'lib/triclops/lock.rb'

# Offense count: 4
# This cop supports safe autocorrection (--autocorrect).
Style/IfUnlessModifier:
Exclude:
- 'app/models/user.rb'
- 'config/routes.rb'
- 'lib/triclops/raster.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
Expand All @@ -225,13 +167,12 @@ Style/RedundantFetchBlock:
Exclude:
- 'config/puma.rb'

# Offense count: 7
# Offense count: 6
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Mode.
Style/StringConcatenation:
Exclude:
- 'app/models/resource.rb'
- 'app/models/user.rb'
- 'spec/models/concerns/triclops/resource/iiif_info_spec.rb'
- 'spec/models/resource_spec.rb'

Expand Down Expand Up @@ -260,7 +201,7 @@ Style/StringLiterals:
- 'spec/triclops/raster_cache_spec.rb'
- 'spec/triclops/raster_spec.rb'

# Offense count: 15
# Offense count: 17
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Expand Down
37 changes: 37 additions & 0 deletions app/controllers/api/v1/resources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,52 @@ def destroy
end
end

# GET /resources
def index
per_page, status, page, identifier = get_index_query_params(index_params[:per_page], index_params[:status], index_params[:page], index_params[:identifier])

resources = Resource
identifier && identifier != 'any' && resources = resources.where(identifier: identifier)
status && status != 'any' && resources = resources.where(status: status)
resources, last_page = find_page(resources, page, per_page)

render json:
{ resources: resources.map(&:attributes), last_page: last_page }
end

private

def find_page(resources, page, per_page)
last_page = per_page * (page - 1) < resources.order(:status).length && per_page * page >= resources.order(:status).length

resources = resources.limit(per_page).offset((page - 1) * per_page)
status && status != 'any' && resources = resources.order(:status)
[resources, last_page]
end

def get_index_query_params(per_page_p, status_p, page_p, identifier_p)
statuses = ['pending', 'processing', 'failure', 'ready']

per_page = per_page_p ? Integer(per_page_p) : 50
param_status = status_p.is_a?(String) ? status_p.downcase : status_p
identifier = identifier_p.is_a?(String) ? identifier_p.downcase : identifier_p
status = statuses.include?(param_status) ? statuses.index(param_status) : param_status
page = page_p ? Integer(page_p) : 1

[per_page, status, page, identifier]
end

def set_resource
@resource = Resource.find_by(identifier: params[:id])
end

def create_params
params.require(:resource).permit(:source_uri, :featured_region, :pcdm_type)
end

def index_params
params.permit(:status, :page, :identifier, :format, :per_page)
end
end
end
end
1 change: 1 addition & 0 deletions app/controllers/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def ensure_json_request
# :forbidden status if the request uses an invalid request token. This method should be
# used as a before_action callback for any controller actions that require authorization.
def authenticate_request_token
return if user_signed_in?
authenticate_or_request_with_http_token do |token, _options|
ActiveSupport::SecurityUtils.secure_compare(TRICLOPS['remote_request_api_key'], token)
end
Expand Down
29 changes: 14 additions & 15 deletions app/javascript/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import React, { useState, useEffect } from 'react';
import '../stylesheets/triclops_v1.scss'; // app css entry point
import { RouterProvider, createBrowserRouter } from 'react-router-dom';
import HomePage from '../pages/Home';
import ResourcesPage from '../pages/Resources';

const App = () => {
const [appVersion, setAppVersion] = useState<string | null>(null);

useEffect(() => {
setAppVersion(document.body.getAttribute('data-app-version'));
}, [appVersion])

if (!appVersion) {
return 'Loading...';
const router = createBrowserRouter([
{
path: '/',
children: [
{ index: true, element: <HomePage /> },
{ path: '/admin/resources', element: <ResourcesPage /> }
]
}
])

return (
<div>
<h1>Triclops</h1>
<p>{`Version ${appVersion}`}</p>
</div>
);
const App = () => {
return <RouterProvider router={router} />;
};

export default App;
Loading
Loading