add strip_split and to_list to core_ext

This commit is contained in:
Alexander Meindl 2022-06-08 20:01:59 +02:00
parent 82f4d081d3
commit fba4415dde
11 changed files with 53 additions and 10 deletions

View File

@ -72,7 +72,7 @@ module AdditionalsQuery
def sql_for_project_identifier_field(field, operator, values)
value = values.first
values = value.split(',').map(&:strip) if ['=', '!'].include?(operator) && value.include?(',')
values = value.strip_split if ['=', '!'].include?(operator) && value.include?(',')
sql_for_field field, operator, values, Project.table_name, 'identifier'
end

View File

@ -12,7 +12,7 @@
.user.line
= l :field_role
' :
= user_roles[user.id].join(', ').html_safe
= user_roles[user.id].to_list.html_safe
.user.line
= l :field_login
' :

View File

@ -51,7 +51,7 @@ en:
global_footer_info: 'Enter a project wide wiki footer here.'
global_sidebar_info: "Enter a project wide available text message here. This sidebar text will be displayed at the project overview, the issue pages and the wiki pages."
global_wiki_sidebar_info: 'Enter a project wide available text message for your wiki sidebar, here. This sidebar text will be displayed at the wiki pages only. Use this space for Macros like "Last changed pages" for example. In case a project specific sidebar is used (wiki page), this will be preferably displayed in the sidebar instead.'
google_maps_embed_api_html: In case you want to use the Gmap macro in order to display Goole maps please implement your Google Maps API key here. Afterwards you can use the macro and various parameters. More information on how to use the paramaters are provided at <a href="https://developers.google.com/maps/documentation/embed/guide" target="_blank">https://developers.google.com/maps/documentation/embed/guide</a>. The Gmap macro works only in combination with the embedded key here.
google_maps_embed_api_html: In case you want to use the Gmap macro in order to display Goole maps please implement your Google Maps API key here. Afterwards you can use the macro and various parameters. More information on how to use the parameters are provided at <a href="https://developers.google.com/maps/documentation/embed/guide" target="_blank">https://developers.google.com/maps/documentation/embed/guide</a>. The Gmap macro works only in combination with the embedded key here.
hidden_macros_in_toolbar_info: All available macros that the logged in user can use are listed via the macro button of the wiki toolbar. Macros marked here are not offered for selection. This allows you to limit the scope of the list.
info_hidden_roles_html: Hidden roles can only be used together with the user visibility "Members of visible projects". If the user is not in a role that is visible to the current user, this role including user is hidden on the project overview page and in query lists.
info_live_search_result_restriction: "LiveSearch results are limited to %{value} entries. Try to filter your search a better way."

View File

@ -51,7 +51,7 @@ ja:
global_footer_info: 'プロジェクト全体のWikiフッターをここに入力する'
global_sidebar_info: "この文章はプロジェクト全体で表示されます。このサイドバーの文章は、プロジェクト概要・チケット関連ページ・Wiki関連ページに表示されます。"
global_wiki_sidebar_info: 'プロジェクト全体のWikiサイドバーで使用される文章を入力する。このサイドバー文章は、Wikiページのみに表示されます。例えば、「直近変更されたページ」等のマクロで使う事をお勧めします。もしプロジェクト特有のサイドバーが使用されている場合でも、こちらの文章がサイドバーで優先的に表示されます。'
google_maps_embed_api_html: In case you want to use the Gmap macro in order to display Goole maps please implement your Google Maps API key here. Afterwards you can use the macro and various parameters. More information on how to use the paramaters are provided at <a href="https://developers.google.com/maps/documentation/embed/guide" target="_blank">https://developers.google.com/maps/documentation/embed/guide</a>. The Gmap macro works only in combination with the embedded key here.
google_maps_embed_api_html: In case you want to use the Gmap macro in order to display Goole maps please implement your Google Maps API key here. Afterwards you can use the macro and various parameters. More information on how to use the parameters are provided at <a href="https://developers.google.com/maps/documentation/embed/guide" target="_blank">https://developers.google.com/maps/documentation/embed/guide</a>. The Gmap macro works only in combination with the embedded key here.
hidden_macros_in_toolbar_info: "ログインしているユーザーが使用できるすべての利用可能なマクロは、wikiツールバーのマクロボタンを使ってリストアップされています。ここでマークされたマクロは選択のために提供されていません。これにより、リストの範囲を制限することができます。"
info_hidden_roles_html: Hidden roles can only be used together with the user visibility "Members of visible projects". If the user is not in a role that is visible to the current user, this role including user is hidden on the project overview page and in query lists.
info_live_search_result_restriction: "LiveSearchの検索結果は %{value} に限定されます。がヒットしました。検索内容をもっと詳しく説明してみてください。"

View File

@ -51,7 +51,7 @@ pl:
global_footer_info: "Wprowadź tutaj szeroką stopkę projektu wiki footer."
global_sidebar_info: "Wprowadź tutaj ogólnodostępną wiadomość tekstową dotyczącą projektu. Ten pasek boczny będzie wyświetlany w przeglądzie projektu, na stronach spraw i na stronach wiki."
global_wiki_sidebar_info: 'Wprowadź ogólnodostępną wiadomość tekstową dla paska bocznego wiki, tutaj. Ten pasek boczny będzie wyświetlany tylko na stronach wiki. Użyj tego miejsca dla makr, jak na przykład "Last changed pages". W przypadku użycia paska bocznego specyficznego dla projektu (strona wiki), zostanie on wyświetlony na pasku bocznym.'
google_maps_embed_api_html: "W przypadku, gdy chcesz użyć makra Gmapy do wyświetlania map Google, zaimplementuj tutaj swój klucz API Google Maps. Następnie możesz użyć makra i różnych parametrów. Więcej informacji na temat korzystania z paramaterów znajduje się na stronie <a href=\"https://developers.google.com/maps/documentation/embed/guide\" target=\"_blank\">https://developers.google.com/maps/documentation/embed/guide</a>. The Gmap macro works only in combination with the embedded key here."
google_maps_embed_api_html: "W przypadku, gdy chcesz użyć makra Gmapy do wyświetlania map Google, zaimplementuj tutaj swój klucz API Google Maps. Następnie możesz użyć makra i różnych parametrów. Więcej informacji na temat korzystania z parameterów znajduje się na stronie <a href=\"https://developers.google.com/maps/documentation/embed/guide\" target=\"_blank\">https://developers.google.com/maps/documentation/embed/guide</a>. The Gmap macro works only in combination with the embedded key here."
hidden_macros_in_toolbar_info: "Wszystkie dostępne makra, których może używać zalogowany użytkownik, są wymienione za pomocą przycisku makro na pasku narzędzi wiki. Makra zaznaczone tutaj nie są oferowane do wyboru. Pozwala to na ograniczenie zakresu listy."
info_hidden_roles_html: Hidden roles can only be used together with the user visibility "Members of visible projects".Jeśli użytkownik nie jest w roli, która jest widoczna dla bieżącego użytkownika, rola ta wraz z użytkownikiem jest ukryta na stronie przeglądu projektu i na listach zapytań.
info_live_search_result_restriction: "Wyniki LiveSearch są ograniczone do %{value} trafienia. Spróbuj opisać swoje poszukiwania bardziej szczegółowo."

View File

@ -51,7 +51,7 @@ pt-BR:
global_footer_info: 'Insira aqui um rodapé do wiki do projeto.'
global_sidebar_info: "Digite aqui uma ampla mensagem de texto disponível para o projeto. Este texto lateral será exibido na visão geral do projeto, nas páginas de tarefas e nas páginas wiki."
global_wiki_sidebar_info: "Digite aqui uma mensagem de texto disponível para o projeto de sua barra lateral wiki. Este texto da barra lateral será exibido apenas nas páginas do wiki. Use este espaço para Macros como \"Last changed pages\", por exemplo. Caso seja usada uma barra lateral específica de um projeto (página wiki), esta será exibida preferencialmente na barra lateral."
google_maps_embed_api_html: "Caso você queira usar a macro Gmap para exibir os mapas Goole, por favor, implemente sua chave API do Google Maps aqui. Em seguida, você pode usar a macro e vários parâmetros. Mais informações sobre como usar os paramaters são fornecidas em <a href=\"https://developers.google.com/maps/documentation/embed/guide\" target=\"_blank\">https://developers.google.com/maps/documentation/embed/guide</a>. A macro Gmap funciona apenas em combinação com a chave embutida aqui."
google_maps_embed_api_html: "Caso você queira usar a macro Gmap para exibir os mapas Goole, por favor, implemente sua chave API do Google Maps aqui. Em seguida, você pode usar a macro e vários parâmetros. Mais informações sobre como usar os parameters são fornecidas em <a href=\"https://developers.google.com/maps/documentation/embed/guide\" target=\"_blank\">https://developers.google.com/maps/documentation/embed/guide</a>. A macro Gmap funciona apenas em combinação com a chave embutida aqui."
hidden_macros_in_toolbar_info: "Todas as macros disponíveis que o usuário logado pode usar são listadas através do botão de macro da barra de ferramentas do wiki. As macros aqui marcadas não são oferecidas para seleção. Isto permite limitar o escopo da lista."
info_hidden_roles_html: "As funções ocultas só podem ser usadas junto com a visibilidade do usuário \"Members of visible projects\". Se o usuário não estiver em uma função que seja visível para o usuário atual, esta função, incluindo o usuário, está oculta na página de síntese do projeto e nas listas de consulta."
info_live_search_result_restriction: "Os resultados do LiveSearch são limitados a %{value}. acertos. Tente descrever sua busca com mais detalhes."

View File

@ -51,7 +51,7 @@ ru:
global_footer_info: "Введите здесь проект в нижний колонтитул вики-проекта."
global_sidebar_info: "Введите сюда широко доступное текстовое сообщение для проекта. Этот текст на боковой панели будет отображаться в обзоре проекта, на страницах задач и вики-страницах."
global_wiki_sidebar_info: 'Enter a project wide available text message for your wiki sidebar, here. This sidebar text will be displayed at the wiki pages only. Use this space for Macros like "Last changed pages" for example. In case a project specific sidebar is used (wiki page), this will be preferably displayed in the sidebar instead.'
google_maps_embed_api_html: In case you want to use the Gmap macro in order to display Goole maps please implement your Google Maps API key here. Afterwards you can use the macro and various parameters. More information on how to use the paramaters are provided at <a href="https://developers.google.com/maps/documentation/embed/guide" target="_blank">https://developers.google.com/maps/documentation/embed/guide</a>. The Gmap macro works only in combination with the embedded key here.
google_maps_embed_api_html: In case you want to use the Gmap macro in order to display Goole maps please implement your Google Maps API key here. Afterwards you can use the macro and various parameters. More information on how to use the parameters are provided at <a href="https://developers.google.com/maps/documentation/embed/guide" target="_blank">https://developers.google.com/maps/documentation/embed/guide</a>. The Gmap macro works only in combination with the embedded key here.
hidden_macros_in_toolbar_info: "Все доступные макросы, которые может использовать вошедший в систему пользователь, перечислены с помощью кнопки макроса на панели инструментов вики. Макросы, отмеченные здесь, не предлагаются для выбора. Это позволяет вам ограничить область действия списка."
info_hidden_roles_html: "Скрытые роли могут использоваться только вместе с видимостью пользователя \"Members of visible projects\". Если пользователь не находится в роли, видимой для текущего пользователя, эта роль, включая пользователя, скрыта на странице обзора проекта и в списках запросов."
info_live_search_result_restriction: "Результаты LiveSearch ограничены %{value} удары. Попробуйте описать свой поиск более подробно."

View File

@ -51,7 +51,7 @@
global_footer_info: "專案中頁尾訊息。"
global_sidebar_info: "專案中側邊訊息。自訂側邊訊息將在專案概觀頁、議題清單頁及Wiki頁顯示。"
global_wiki_sidebar_info: "專案中Wiki側邊訊息。僅在wiki頁內顯示。可輸入如 \"Last changed pages\" 等macro指令。若專案內使用指定的Wiki側邊訊息則該優先顯示該訊息。"
google_maps_embed_api_html: In case you want to use the Gmap macro in order to display Goole maps please implement your Google Maps API key here. Afterwards you can use the macro and various parameters. More information on how to use the paramaters are provided at <a href="https://developers.google.com/maps/documentation/embed/guide" target="_blank">https://developers.google.com/maps/documentation/embed/guide</a>. The Gmap macro works only in combination with the embedded key here.
google_maps_embed_api_html: In case you want to use the Gmap macro in order to display Goole maps please implement your Google Maps API key here. Afterwards you can use the macro and various parameters. More information on how to use the parameters are provided at <a href="https://developers.google.com/maps/documentation/embed/guide" target="_blank">https://developers.google.com/maps/documentation/embed/guide</a>. The Gmap macro works only in combination with the embedded key here.
hidden_macros_in_toolbar_info: All available macros that the logged in user can use are listed via the macro button of the wiki toolbar. Macros marked here are not offered for selection. This allows you to limit the scope of the list.
info_hidden_roles_html: Hidden roles can only be used together with the user visibility "Members of visible projects". If the user is not in a role that is visible to the current user, this role including user is hidden on the project overview page and in query lists.
info_live_search_result_restriction: "LiveSearch的结果仅限于 %{value}。命中率。尝试更详细地描述你的搜索。"

View File

@ -49,7 +49,7 @@ module Additionals
def split_ids(phrase, limit: nil)
limit ||= Setting.per_page_options_array.first || 25
raw_ids = phrase.split(',').map(&:strip)
raw_ids = phrase.strip_split
ids = []
raw_ids.each do |id|
if id.include? '-'
@ -183,3 +183,16 @@ module Additionals
end
end
end
class String
def strip_split(sep = ',')
split(sep).map(&:strip).compact_blank
end
end
class Array
# alias for join with ', ' as seperator
def to_list
join ', '
end
end

View File

@ -42,7 +42,7 @@ module Additionals
def live_search_title_info(entity)
fields = "LiveSearch::#{entity.to_s.classify}".constantize.info_fields
all_fields = fields.map { |f| "#{f}:term" }.join ', '
all_fields = fields.map { |f| "#{f}:term" }.to_list
l :label_live_search_hints, value: all_fields
end

View File

@ -0,0 +1,30 @@
# frozen_string_literal: true
require File.expand_path '../../test_helper', __FILE__
class CoreExtTest < Additionals::TestCase
def test_strip_split_with_default_sep
assert_equal ['me@localhost',
'you@localhost',
'invalid@localhost@me',
'others@localhost'],
'me@localhost,you@localhost, invalid@localhost@me , others@localhost'.strip_split
end
def test_strip_split_with_custom_sep
assert_equal ['me@localhost', 'you@localhost'], 'me@localhost;you@localhost'.strip_split(';')
end
def test_strip_split_with_empty_string
assert ''.strip_split.is_a? Array
assert_empty ''.strip_split
end
def test_to_list
assert_equal 'me@localhost, you@localhost', ['me@localhost', 'you@localhost'].to_list
end
def test_to_list_with_empty_array
assert_equal '', [].to_list
end
end