From: Matthew Horsfall (alh) Date: Tue, 26 Jul 2011 20:24:25 +0000 (-0400) Subject: Introducing a very barebones admin UI for managing buckets. I would X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FApp-IdiotBox.git;a=commitdiff_plain;h=26b4958ec93a29fb6918934f2b4fab0541bad2fd;hp=8ee9b216399777fbcb5e307b28c8dcfcd3716dd3 Introducing a very barebones admin UI for managing buckets. I would avoid using the delete action on active buckets for now as it does not clean up videos/announcements or files on disk --- diff --git a/lib/App/IdiotBox.pm b/lib/App/IdiotBox.pm index 081327e..a915049 100644 --- a/lib/App/IdiotBox.pm +++ b/lib/App/IdiotBox.pm @@ -66,6 +66,55 @@ sub BUILD { sub dispatch_request { my $self = shift; sub (/) { $self->show_front_page }, + sub (/admin/) { + sub (%new_name=&new_slug=) { + my ($self, $name, $slug) = @_; + + unless ($name && $slug) { + return $self->show_admin_page(error => "Please enter a name and a bucket"); + } + if ($name =~ /^\s+$/ || $slug =~ /^\s+$/) { + return $self->show_admin_page(error => "Names/buckets must not be all whitespace"); + } + + $slug =~ s/ /-/g; + + my $nb = $self->buckets->add(bless({ + slug => $slug, + name => $name, + }, 'App::IdiotBox::Bucket')); + + $self->show_admin_page; + }, + }, + sub (/admin/) { $self->show_admin_page }, + + sub (/admin/*/...) { + my $bucket = $self->buckets->get({ slug => $_[1] }); + sub (%new_name=) { + my ($self, $new_name) = @_; + if (!$new_name) { + return $self->show_edit_bucket_page($bucket, error => "Please enter a new name"); + } elsif ($new_name =~ /^\s+$/) { + return $self->show_edit_bucket_page($bucket, error => "Names must not be all whitespace"); + } + $self->buckets->replace($bucket, bless({ + slug => $bucket->slug, + name => $new_name, + }, 'App::IdiotBox::Bucket')); + $self->show_bucket_edited_page($bucket); + }, + sub (/) { + $self->show_edit_bucket_page($bucket); + }, + sub (/delete/) { + $self->show_confirm_delete_bucket_page($bucket) + }, + sub (/delete/yes/) { + $self->buckets->remove({ slug => $bucket->slug }); + $self->show_bucket_deleted_page($bucket->slug); + }, + }, sub (/*/...) { my $bucket = $self->buckets->get({ slug => $_[1] }); sub (/) { @@ -101,6 +150,68 @@ sub show_front_page { ); } +sub show_admin_page { + my $self = shift; + my %opts = @_; + my $error = $opts{error} || ''; + + my $bucket = $self->buckets; + $self->html_response( + admin => sub { + $_->select('#bucket-list') + ->repeat_content($bucket->map(sub { + my $obj = $_; + sub { + $_->select('.bucket-slug')->replace_content($obj->slug) + ->select('.bucket-name')->replace_content($obj->name) + ->select('.edit-link')->set_attribute( + 'href' => $obj->slug.'/' + ) + ->select('.delete-link')->set_attribute( + 'href' => $obj->slug.'/delete/' + ) + } + })) + ->select('.error-text')->replace_content($error) + + } + + ); +} + +sub show_confirm_delete_bucket_page { + my ($self, $bucket) = @_; + $self->html_response('delete' => sub { + $_->select('.bucket-name')->replace_content($bucket->name) + ->select('.confirm-yes')->set_attribute( + 'href' => 'yes/' + ) + }); +} + +sub show_edit_bucket_page { + my ($self, $bucket, %opt) = @_; + my $error = $opt{error} || ''; + $self->html_response('edit' => sub { + $_->select('.bucket-name')->replace_content($bucket->name) + ->select('.error-text')->replace_content($error); + }); +} + +sub show_bucket_deleted_page { + my ($self, $name) = @_; + $self->html_response('deleted' => sub { + $_->select('.bucket-name')->replace_content($name) + }); +} + +sub show_bucket_edited_page { + my ($self, $name) = @_; + $self->html_response('edited' => sub { + $_->select('.bucket-name')->replace_content($name) + }); +} + sub show_bucket { my ($self, $bucket) = @_; $self->html_response(bucket => sub { diff --git a/lib/App/IdiotBox/Store/SQLite.pm b/lib/App/IdiotBox/Store/SQLite.pm index 104472b..be69881 100644 --- a/lib/App/IdiotBox/Store/SQLite.pm +++ b/lib/App/IdiotBox/Store/SQLite.pm @@ -128,8 +128,13 @@ sub _bind_buckets { (slug, name) VALUES (?, ?) - } - + }, + delete_one => q{ + DELETE FROM buckets WHERE slug = ? + }, + update_one => q{ + UPDATE buckets SET slug = ?, name = ? WHERE slug = ? + }, } ) } diff --git a/share/html/admin.html b/share/html/admin.html new file mode 100644 index 0000000..00e594b --- /dev/null +++ b/share/html/admin.html @@ -0,0 +1,44 @@ +
+ +

+ List of available buckets +

+

+ Add a new bucket +

+
+ +

+ +

+ +
+ Some error +

+ Below is a list of existing buckets. Click on the buckets to change details about them, and 'Delete' to remove them. +

+ +
+ +
+

+ THIS IZ MAI BUKKIT +

+ +
+ + + diff --git a/share/html/delete.html b/share/html/delete.html new file mode 100644 index 0000000..45f85ee --- /dev/null +++ b/share/html/delete.html @@ -0,0 +1,13 @@ +
+ +
+

+ Do you really want to delete this bucket: +

+ THIS IZ MAI BUKKIT + Yes +

No +
+ + +
diff --git a/share/html/deleted.html b/share/html/deleted.html new file mode 100644 index 0000000..41acd38 --- /dev/null +++ b/share/html/deleted.html @@ -0,0 +1,10 @@ +
+ +
+

+ The bucket was deleted. Say good by to THIS IZ MAI BUKKIT +

+
+ + +
diff --git a/share/html/edit.html b/share/html/edit.html new file mode 100644 index 0000000..8a11a37 --- /dev/null +++ b/share/html/edit.html @@ -0,0 +1,23 @@ +
+ +
+

+ Editing bucket THIS IZ MAI BUKKIT +

+ +
+ +

+ + +
+ Some error +
+ + +
diff --git a/share/html/edited.html b/share/html/edited.html new file mode 100644 index 0000000..5f34a6a --- /dev/null +++ b/share/html/edited.html @@ -0,0 +1,10 @@ +
+ +
+

+ The bucket was modifed. +

+
+ + +
diff --git a/share/skin/presentingperl/html/admin.html b/share/skin/presentingperl/html/admin.html new file mode 100644 index 0000000..00e594b --- /dev/null +++ b/share/skin/presentingperl/html/admin.html @@ -0,0 +1,44 @@ +
+ +

+ List of available buckets +

+

+ Add a new bucket +

+
+ +

+ +

+ +
+ Some error +

+ Below is a list of existing buckets. Click on the buckets to change details about them, and 'Delete' to remove them. +

+ +
+ +
+

+ THIS IZ MAI BUKKIT +

+ +
+ + + diff --git a/share/skin/presentingperl/html/delete.html b/share/skin/presentingperl/html/delete.html new file mode 100644 index 0000000..45f85ee --- /dev/null +++ b/share/skin/presentingperl/html/delete.html @@ -0,0 +1,13 @@ +
+ +
+

+ Do you really want to delete this bucket: +

+ THIS IZ MAI BUKKIT + Yes +

No +
+ + +
diff --git a/share/skin/presentingperl/html/deleted.html b/share/skin/presentingperl/html/deleted.html new file mode 100644 index 0000000..41acd38 --- /dev/null +++ b/share/skin/presentingperl/html/deleted.html @@ -0,0 +1,10 @@ +
+ +
+

+ The bucket was deleted. Say good by to THIS IZ MAI BUKKIT +

+
+ + +
diff --git a/share/skin/presentingperl/html/edit.html b/share/skin/presentingperl/html/edit.html new file mode 100644 index 0000000..8a11a37 --- /dev/null +++ b/share/skin/presentingperl/html/edit.html @@ -0,0 +1,23 @@ +
+ +
+

+ Editing bucket THIS IZ MAI BUKKIT +

+ +
+ +

+ + +
+ Some error +
+ + +
diff --git a/share/skin/presentingperl/html/edited.html b/share/skin/presentingperl/html/edited.html new file mode 100644 index 0000000..5f34a6a --- /dev/null +++ b/share/skin/presentingperl/html/edited.html @@ -0,0 +1,10 @@ +
+ +
+

+ The bucket was modifed. +

+
+ + +
diff --git a/share/skin/presentingperl/static/style/layout.css b/share/skin/presentingperl/static/style/layout.css index 9b47e34..c2fe2a5 100644 --- a/share/skin/presentingperl/static/style/layout.css +++ b/share/skin/presentingperl/static/style/layout.css @@ -75,4 +75,11 @@ border-top: 1px dashed #336699; } +.delete-link { + float: right; +} +.error-text { + color: red; + font-weight: bold; +}