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

Polish up search endpoint archive and delete use cases #1257

Merged
merged 3 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="modal-header">
<button type="button" class="close btn-core-close" ng-click="ctrl.cancel()" aria-label="Close"></button>
<h3 class="modal-title">Archive This Search Endpoint for Later?</h3>
</div>
<div class="modal-body">
<p>You're about to put this search endpoint into deep freeze. You'll be able to unarchive it later through the "Archived Search Endpoint" filter in the Search Endpoint Listings.</p>
</div>
<div class="modal-footer">
<button class="btn btn-danger" ng-click="ctrl.ok()">Archive</button>
<button class="btn btn-default" ng-click="ctrl.cancel()">Cancel</button>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="modal-header">
<button type="button" class="close btn-core-close" ng-click="ctrl.cancel()" aria-label="Close"></button>
<h3 class="modal-title">Delete This Search Endpoint</h3>
</div>
<div class="modal-body">
<p>You're about to delete this Search Endpoint forever! If you think you might want it later, use the Archive function instead.</p>
</div>
<div class="modal-footer">
<button class="btn btn-danger" ng-click="ctrl.ok()">Delete</button>
<button class="btn btn-default" ng-click="ctrl.cancel()">Cancel</button>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<a class="action-icon" ng-click="ctrl.openDeleteModal()">
<i
class="glyphicon glyphicon-trash"
aria-hidden="true"
title="Delete"
alt="Delete"
></i>
</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'use strict';

/*jshint latedef:false*/

angular.module('QuepidApp')
.controller('DeleteSearchEndpointCtrl', [
'$scope',
'$uibModal',
'flash',
'searchEndpointSvc',
function (
$scope,
$uibModal,
flash,
searchEndpointSvc
) {
var ctrl = this;

ctrl.thisSearchEndpoint = $scope.thisSearchEndpoint;
ctrl.deleteSearchEndpoint = deleteSearchEndpoint;
ctrl.openDeleteModal = openDeleteModal;

function deleteSearchEndpoint() {
searchEndpointSvc.deleteSearchEndpoint(ctrl.thisSearchEndpoint).then(
function () {
flash.success = 'Search Endpoint deleted successfully.';
}, function (data) {
var message = 'Oooops! Could not delete the Search Endpoint. ';
message += data.message;
flash.error = message;
}
);
}

function openDeleteModal() {
var modalInstance = $uibModal.open({
templateUrl: 'delete_search_endpoint/_modal.html',
controller: 'DeleteSearchEndpointModalInstanceCtrl',
controllerAs: 'ctrl',
size: 'sm',
resolve: {}
});

modalInstance.result.then(function (deleteClicked) {
if( deleteClicked ){
ctrl.deleteSearchEndpoint();
}
});
}
}
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

angular.module('QuepidApp')
.directive('deleteSearchEndpoint', [
function () {
return {
restrict: 'E',
controller: 'DeleteSearchEndpointCtrl',
controllerAs: 'ctrl',
templateUrl: 'delete_search_endpoint/delete_search_endpoint.html',
scope: {
thisSearchEndpoint: '=',
},
};
}
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

angular.module('QuepidApp')
.controller('DeleteSearchEndpointModalInstanceCtrl', [
'$rootScope',
'$uibModalInstance',
function ($rootScope, $uibModalInstance) {
var ctrl = this;

ctrl.ok = function () {
$uibModalInstance.close(true);
};

ctrl.cancel = function () {
$uibModalInstance.close(false);
};

}
]);
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
alt="Edit"
></i>
</a>
<delete-search-endpoint this-search-endpoint="ctrl.searchEndpoint"></delete-search-endpoint>
<archive-search-endpoint this-search-endpoint="ctrl.searchEndpoint"></archive-search-endpoint>
</span>
</div>
Expand Down
16 changes: 16 additions & 0 deletions app/assets/javascripts/services/searchEndpointSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,21 @@ angular.module('QuepidApp')
});
};

this.deleteSearchEndpoint = function(searchEndpointToDelete) {
var self = this;

return $http.delete('api/search_endpoints/' + searchEndpointToDelete.id)
.then(function() {
//that.refetchCaseLists();
var indexOfSearchEndpoint = self.searchEndpoints.indexOf( self.searchEndpoints.filter( function (item) {
return item.id === searchEndpointToDelete.id;
})[0] );
self.searchEndpoints.splice(indexOfSearchEndpoint, 1);

broadcastSvc.send('updatedSearchEndpointsList', self.searchEndpoints);

});
};

}
]);
2 changes: 1 addition & 1 deletion app/controllers/api/v1/search_endpoints_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Api
module V1
class SearchEndpointsController < Api::ApiController
before_action :set_search_endpoint, only: [ :show, :update ]
before_action :set_search_endpoint, only: [ :show, :update, :destroy ]

def_param_group :search_endpoint_params do
param :search_endpoint, Hash, required: true do
Expand Down
13 changes: 11 additions & 2 deletions app/controllers/search_endpoints_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

class SearchEndpointsController < ApplicationController
include Pagy::Backend
before_action :set_search_endpoint, only: [ :show, :edit, :update, :destroy, :clone ]
before_action :set_search_endpoint, only: [ :show, :edit, :update, :destroy, :clone, :archive ]

respond_to :html

def index
bool = ActiveRecord::Type::Boolean.new
@archived = bool.deserialize(params[:archived] || false )

query = @current_user.search_endpoints_involved_with.order(updated_at: :desc)
query = query.where(archived: @archived)

query = query.where(owner_id: current_user.id) if params[:owned].present?
query = query.where(teams: { id: params[:team_id] }) if params[:team_id].present?
Expand Down Expand Up @@ -35,6 +39,11 @@ def clone
respond_with(@search_endpoint)
end

def archive
@search_endpoint.mark_archived!
redirect_to search_endpoints_path, notice: 'Search Endpoint was archived.'
end

def edit
end

Expand Down Expand Up @@ -69,7 +78,7 @@ def update

def destroy
@search_endpoint.destroy
respond_with(@search_endpoint)
redirect_to search_endpoints_path, notice: 'Search Endpoint was deleted.'
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/views/home/case_prophet.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<turbo-frame id="case_frame_<%= @case.id %>">
<h5 class="card-title">
<%= number_with_precision(@case.last_score.score, precision: 2) unless @case.scores.empty? %>
<%= @case.scorer.name %>
<%= @case.scorer&.name %>
</h5>
<p class="card-text">
<% if @case.scores.empty? %>
Expand Down
10 changes: 6 additions & 4 deletions app/views/search_endpoints/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1>Edit Search Endpoint <%= @search_endpoint.fullname %></h1>
<h1>Edit Search Endpoint</h1>
<div class="btn-toolbar mb-2 mb-md-0">
<div class="btn-group me-2">
<%= button_to "Delete this Search Endpoint", @search_endpoint, method: :delete, class: 'btn btn-sm btn-outline-danger', onclick: "return confirm('Are you sure you want to delete this Search Endpoint?');" %>
<%= link_to "Back to Search Endpoints", search_endpoints_path, class: "btn btn-sm btn-outline-secondary" %>
<%= button_to "Delete", @search_endpoint, method: :delete, class: 'btn btn-sm btn-outline-danger', onclick: "return confirm('Are you sure you want to delete this Search Endpoint?');" %>
<%= button_to "Archive", archive_search_endpoint_path(@search_endpoint), method: :post, class: 'btn btn-sm btn-outline-warning', onclick: "return confirm('Are you sure you want to archive this Search Endpoint?');" %>
</div>


<%= link_to "Back", search_endpoints_path, class: "btn btn-sm btn-outline-secondary" %>

</div>
</div>

Expand Down
16 changes: 13 additions & 3 deletions app/views/search_endpoints/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Search Endpoints represents a search engine (or API!) that is receiving queries
<div class="card h-100">
<div class="card-header">
<%= form_tag(search_endpoints_path, { method: :get }) do %>
<div class="mb-0 d-flex fs-6 ">
<div class="mb-0 d-flex fs-6 justify-content-center">

<div class="input-group">
<%= text_field_tag :q, params[:q],
Expand All @@ -32,7 +32,8 @@ Search Endpoints represents a search engine (or API!) that is receiving queries
<i class="bi bi-search-heart"></i>
<% end %>
</div>
<div class="d-flex flex-row justify-content-between">

<div class="d-flex justify-content-between">
<label class="ms-2">Mine</label>
<%= check_box_tag :owned,
true,
Expand All @@ -41,7 +42,16 @@ Search Endpoints represents a search engine (or API!) that is receiving queries
onchange: 'this.form.submit()'
%>
</div>
<div class="d-flex">
<div class="d-flex flex-row justify-content-between">
<label class="ms-2">Archived?</label>
<%= check_box_tag :archived,
true,
params[:archived].present?,
class: 'ms-2 form-check-input form-check-input-sm',
onchange: 'this.form.submit()'
%>
</div>
<div class="d-flex justify-content-between">
<%= select_tag :team_id,
options_for_select(
[['Team', '']] + @current_user.teams.map { |j| [j.name, j.id] },
Expand Down
4 changes: 2 additions & 2 deletions app/views/search_endpoints/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<div class="btn-toolbar mb-2 mb-md-0">
<div class="btn-group me-2">
<%= link_to 'Edit', edit_search_endpoint_path(@search_endpoint), class: "btn btn-sm btn-outline-primary " %>
<%= link_to 'Clone', clone_search_endpoint_path(@search_endpoint), method: :post, data: { turbo: false }, class: "btn btn-sm btn-outline-secondary" %>
<%= link_to "Back to Search Endpoints", search_endpoints_path, class: "btn btn-sm btn-outline-secondary" %>
<%= link_to 'Clone', clone_search_endpoint_path(@search_endpoint), method: :post, data: { turbo: false }, class: "btn btn-sm btn-outline-secondary" %>
</div>
<%= link_to "Back", search_endpoints_path, class: "btn btn-sm btn-outline-secondary" %>
</div>
</div>

Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
resources :search_endpoints do
member do
get 'clone'
post 'archive'
end
end

Expand Down