From dbfeee93dd769093cf0b2b3d694f6dc09d85be97 Mon Sep 17 00:00:00 2001 From: pessi-v Date: Thu, 11 Jul 2024 16:16:37 +0200 Subject: [PATCH] save last work --- app/assets/stylesheets/application.scss | 1 + app/assets/stylesheets/components/_btn.scss | 55 +++++++++++++++++++ app/helpers/HTTPRequests_helper.rb | 61 +++++++++++++++++++++ app/views/sources/_form.html.slim | 3 + app/views/sources/index.html.slim | 8 +-- 5 files changed, 124 insertions(+), 4 deletions(-) create mode 100644 app/assets/stylesheets/components/_btn.scss create mode 100644 app/helpers/HTTPRequests_helper.rb diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 99dc31d..1114c20 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -6,6 +6,7 @@ @import "config/reset"; // Components +@import "components/btn"; @import "components/content_menu_bar"; @import "components/search_bar"; @import "components/subtitle"; diff --git a/app/assets/stylesheets/components/_btn.scss b/app/assets/stylesheets/components/_btn.scss new file mode 100644 index 0000000..e5b7331 --- /dev/null +++ b/app/assets/stylesheets/components/_btn.scss @@ -0,0 +1,55 @@ +.btn { + // All the previous code + + &--primary { + color: var(--color-white); + background-image: linear-gradient(to right, var(--color-primary), var(--color-primary-rotate)); + + &:hover, + &:focus, + &:focus-within, + &:active { + color: var(--color-white); + filter: saturate(1.4) brightness(115%); + } + } + + &--secondary { + color: var(--color-white); + background-image: linear-gradient(to right, var(--color-secondary), var(--color-secondary-rotate)); + + &:hover, + &:focus, + &:focus-within, + &:active { + color: var(--color-white); + filter: saturate(1.2) brightness(110%); + } + } + + &--light { + color: var(--color-dark); + background-color: var(--color-light); + + &:hover, + &:focus, + &:focus-within, + &:active { + color: var(--color-dark); + filter: brightness(92%); + } + } + + &--dark { + color: var(--color-white); + border-color: var(--color-dark); + background-color: var(--color-dark); + + &:hover, + &:focus, + &:focus-within, + &:active { + color: var(--color-white); + } + } +} \ No newline at end of file diff --git a/app/helpers/HTTPRequests_helper.rb b/app/helpers/HTTPRequests_helper.rb new file mode 100644 index 0000000..03824b6 --- /dev/null +++ b/app/helpers/HTTPRequests_helper.rb @@ -0,0 +1,61 @@ +module HTTPRequestsHelper + def self.make_request(source: nil, url: nil) + connection = Faraday.new( + url: source&.url || url, + headers: { + 'If-Modified-Since': source&.last_modified, + 'If-None-Match': source&.etag, + 'User-Agent': 'Mozilla/5.0 (X11; Linux i686; rv:127.0) Gecko/20100101 Firefox/127.0' + }, + ssl: { verify: false } + ) do |faraday| + faraday.use FaradayMiddleware::FollowRedirects + faraday.adapter :net_http # not sure if this is needed/helpful + end + + response = connection.get + + if response.status == 500 + source.update(last_error_status: 'Internal Server Error (500)') if source + end + + response + + rescue Faraday::ConnectionFailed => e + puts source.name if source + puts source.url if source + puts e + puts "URL DIDN'T WORK" + source.update(last_error_status: 'connection_failed') if source + return + rescue URI::InvalidURIError => e + puts source.name if source + puts source.url if source + puts e + puts 'INVALID URL' + source.update(last_error_status: 'invalid_url') if source + return + rescue Faraday::SSLError => e + puts source.name if source + puts source.url if source + puts e + puts 'SSL ERROR' + source.update(last_error_status: 'ssl_error') if source + return + rescue Faraday::TimeoutError => e + puts source.name if source + puts source.url if source + puts e + puts 'TIMEOUT ERROR' + source.update(last_error_status: 'timeout') if source + return + rescue FaradayMiddleware::RedirectLimitReached => e + puts source.name if source + puts source.url if source + puts e + puts 'REDIRECT LIMIT REACHED' + source.update(last_error_status: 'redirect_limit_reached') if source + return + end +end + diff --git a/app/views/sources/_form.html.slim b/app/views/sources/_form.html.slim index e4f9583..5646a11 100644 --- a/app/views/sources/_form.html.slim +++ b/app/views/sources/_form.html.slim @@ -33,5 +33,8 @@ = form.label :allow_audio, style: "display: block" = form.check_box :allow_audio + div + = link_to 'cancel', sources_path, class: 'btn btn--primary' + div = form.submit diff --git a/app/views/sources/index.html.slim b/app/views/sources/index.html.slim index 52fce53..40fead7 100644 --- a/app/views/sources/index.html.slim +++ b/app/views/sources/index.html.slim @@ -23,10 +23,10 @@ = @article_counts_by_day[index] - = turbo_frame_tag 'sources' - .list_view_desktop - = turbo_frame_tag 'new_source' - = render @sources + .list_view_desktop + = turbo_frame_tag 'sources', class: 'list_view_desktop' + = turbo_frame_tag 'new_source' + = render @sources / - @sources.each do |source| / = link_to(source) do / = render source