Skip to content

Commit

Permalink
Commit one
Browse files Browse the repository at this point in the history
commit-id:85a93534
  • Loading branch information
brand-it committed Apr 12, 2024
1 parent b6bab40 commit 236ea2c
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 22 deletions.
11 changes: 7 additions & 4 deletions app/assets/stylesheets/bg_process.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
.bg-processes {
position: fixed;
right: 0;
bottom: 0;
z-index: 4;
}

.bg-process {
--bs-toast-bg: rgba(var(--bs-body-bg-rgb), 0.85);
--bs-toast-border-color: var(--bs-border-color-translucent);
Expand All @@ -18,17 +25,13 @@
background-color: $dark-black;
border-radius: var(--bs-toast-border-radius);
border: var(--bs-toast-border-width) solid var(--bs-toast-border-color);
bottom: 0;
box-shadow: var(--bs-toast-box-shadow);
color: var(--bs-toast-color);
font-size: var(--bs-toast-font-size);
margin: 2em;
max-width: 100%;
pointer-events: auto;
position: fixed;
right: 0;
width: var(--bs-toast-max-width);
z-index: 4;

.header {
display: flex;
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class MoviesController < ApplicationController
def show
@movie = movie
@disks = CreateDisksService.call
@disks = FindExistingDisksService.call || CreateDisksService.call
end

def create
Expand Down
23 changes: 23 additions & 0 deletions app/services/find_existing_disks_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

class FindExistingDisksService
MOUNT_LINE = %r{\A(?<disk_name>[a-zA-Z/0-9]+)\son\s(/Volumes/|)(?<name>[a-zA-Z/0-9]+)}
class << self
delegate :call, to: :new
end

# example line:
# /dev/disk4 on /Volumes/PLANET51 (udf, local, nodev, nosuid, read-only, noowners)
def call
mounts = `mount`
disks = []
mounts.each_line do |line|
next unless line.start_with?('/dev/')

match = line.match(MOUNT_LINE)
rdisk_name = match[:disk_name].gsub('/dev/', '/dev/r')
disks << Disk.find_by(name: match[:name], disk_name: [match[:disk_name], rdisk_name])
end
disks.compact
end
end
40 changes: 24 additions & 16 deletions app/views/layouts/application.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,33 @@
<%= render 'layouts/head' %>
</head>
<body>
<%= render ProcessComponent.new worker: ScanPlexWorker do |c| %>
<%= c.with_body do %>
<% if ScanPlexWorker.job.pending? %>
<%=
render(
ProgressBarComponent.new(
model: Movie,
completed: (ScanPlexWorker.job.worker.completed.zero? ? 20 : ScanPlexWorker.job.worker.completed),
status: :success,
message: 'scanning plex for movies',
show_percentage: false
<div class="bg-processes">
<%= render ProcessComponent.new worker: ScanPlexWorker do |c| %>
<%= c.with_body do %>
<% if ScanPlexWorker.job.pending? %>
<%=
render(
ProgressBarComponent.new(
model: Movie,
completed: (ScanPlexWorker.job.worker.completed.zero? ? 20 : ScanPlexWorker.job.worker.completed),
status: :success,
message: 'scanning plex for movies',
show_percentage: false
)
)
)
%>
<% else %>
<span>Done! you have a total of <%= pluralize(Video.count, 'video') %> on plex.</span>
%>
<% else %>
<span>Done! you have a total of <%= pluralize(Video.count, 'video') %> on plex.</span>
<% end %>
<% end %>
<% end %>
<% end %>

<%= render ProcessComponent.new worker: LoadDiskWorker do |c| %>
<%= c.with_body do %>
<span>Loading the disk info</span>
<% end %>
<% end %>
</div>

<div class="d-flex w-100 h-90 mx-auto flex-column">
<%= render ToastComponent.new do |c| %>
Expand Down
15 changes: 14 additions & 1 deletion app/workers/load_disk_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

class LoadDiskWorker < ApplicationWorker
def perform
CreateDisksService.call
cable_ready[DiskTitleChannel.channel_name].morph \
selector: "##{component.dom_id}",
html: render(component, layout: false)
cable_ready.broadcast
end

def component
component = ProcessComponent.new(worker: ScanPlexWorker)
component.with_body { disks.map(&:name).join(', ') }
component
end

def disks
@disks ||= FindExistingDisksService.call || CreateDisksService.call
end
end

0 comments on commit 236ea2c

Please sign in to comment.