Prompt for the new filter name when only copying one.
This also reworks 'Pref_Filters' a bit so it's easier to retrieve filter titles.
This commit is contained in:
@@ -258,7 +258,7 @@ class Pref_Filters extends Handler_Protected {
|
|||||||
];
|
];
|
||||||
|
|
||||||
foreach ($filters as $filter) {
|
foreach ($filters as $filter) {
|
||||||
$name = $this->_get_name($filter->id);
|
$details = $this->_get_details($filter->id);
|
||||||
|
|
||||||
if ($filter_search &&
|
if ($filter_search &&
|
||||||
mb_stripos($filter->title, $filter_search) === false &&
|
mb_stripos($filter->title, $filter_search) === false &&
|
||||||
@@ -273,8 +273,9 @@ class Pref_Filters extends Handler_Protected {
|
|||||||
$item = [
|
$item = [
|
||||||
'id' => 'FILTER:' . $filter->id,
|
'id' => 'FILTER:' . $filter->id,
|
||||||
'bare_id' => $filter->id,
|
'bare_id' => $filter->id,
|
||||||
'name' => $name[0],
|
'bare_name' => $details['title'],
|
||||||
'param' => $name[1],
|
'name' => $details['title_summary'],
|
||||||
|
'param' => $details['actions_summary'],
|
||||||
'checkbox' => false,
|
'checkbox' => false,
|
||||||
'last_triggered' => $filter->last_triggered ? TimeHelper::make_local_datetime($filter->last_triggered) : null,
|
'last_triggered' => $filter->last_triggered ? TimeHelper::make_local_datetime($filter->last_triggered) : null,
|
||||||
'enabled' => sql_bool_to_bool($filter->enabled),
|
'enabled' => sql_bool_to_bool($filter->enabled),
|
||||||
@@ -745,9 +746,9 @@ class Pref_Filters extends Handler_Protected {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<int, string>
|
* @return array{'title': string, 'title_summary': string, 'actions_summary': string}
|
||||||
*/
|
*/
|
||||||
private function _get_name(int $id): array {
|
private function _get_details(int $id): array {
|
||||||
|
|
||||||
$filter = ORM::for_table("ttrss_filters2")
|
$filter = ORM::for_table("ttrss_filters2")
|
||||||
->table_alias('f')
|
->table_alias('f')
|
||||||
@@ -763,10 +764,11 @@ class Pref_Filters extends Handler_Protected {
|
|||||||
->find_one();
|
->find_one();
|
||||||
|
|
||||||
if ($filter) {
|
if ($filter) {
|
||||||
|
$title = $filter->title ?: __('[No caption]');
|
||||||
$title_summary = [
|
$title_summary = [
|
||||||
sprintf(
|
sprintf(
|
||||||
_ngettext("%s (%d rule)", "%s (%d rules)", (int) $filter->num_rules),
|
_ngettext("%s (%d rule)", "%s (%d rules)", (int) $filter->num_rules),
|
||||||
($filter->title ? $filter->title : __("[No caption]")),
|
$title,
|
||||||
$filter->num_rules)];
|
$filter->num_rules)];
|
||||||
|
|
||||||
if ($filter->match_any_rule) array_push($title_summary, __("matches any rule"));
|
if ($filter->match_any_rule) array_push($title_summary, __("matches any rule"));
|
||||||
@@ -805,7 +807,11 @@ class Pref_Filters extends Handler_Protected {
|
|||||||
"<li class='text-muted'><em>" . sprintf(_ngettext("(+%d action)", "(+%d actions)", $actions_not_shown), $actions_not_shown)) . "</em></li>";
|
"<li class='text-muted'><em>" . sprintf(_ngettext("(+%d action)", "(+%d actions)", $actions_not_shown), $actions_not_shown)) . "</em></li>";
|
||||||
}
|
}
|
||||||
|
|
||||||
return [implode(", ", $title_summary), implode("", $actions_summary)];
|
return [
|
||||||
|
'title' => $title,
|
||||||
|
'title_summary' => implode(', ', $title_summary),
|
||||||
|
'actions_summary' => implode('', $actions_summary),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
|
|||||||
@@ -171,13 +171,23 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio
|
|||||||
const sel_rows = this.getSelectedFilters();
|
const sel_rows = this.getSelectedFilters();
|
||||||
|
|
||||||
if (sel_rows.length > 0) {
|
if (sel_rows.length > 0) {
|
||||||
if (confirm(__("Copy selected filters?"))) {
|
const query = {op: "Pref_Filters", method: "copy", ids: sel_rows.toString()};
|
||||||
Notify.progress("Copying selected filters...");
|
let proceed = false;
|
||||||
|
|
||||||
const query = {
|
if (sel_rows.length === 1) {
|
||||||
op: "Pref_Filters", method: "copy",
|
const selected_filter = this.model.getCheckedItems()[0];
|
||||||
ids: sel_rows.toString()
|
const new_title = prompt(__("Name for copied filter:"), 'Copy - ' + this.model.store.getValue(selected_filter, "bare_name"));
|
||||||
};
|
|
||||||
|
if (new_title) {
|
||||||
|
query.new_title = new_title;
|
||||||
|
proceed = true;
|
||||||
|
}
|
||||||
|
} else if (sel_rows.length > 1) {
|
||||||
|
proceed = confirm(__("Copy selected filters?"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (proceed) {
|
||||||
|
Notify.progress("Copying selected filters...");
|
||||||
|
|
||||||
xhr.post("backend.php", query, () => {
|
xhr.post("backend.php", query, () => {
|
||||||
this.reload();
|
this.reload();
|
||||||
|
|||||||
Reference in New Issue
Block a user