Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
birger
users
Commits
fe03ab20
Commit
fe03ab20
authored
May 27, 2021
by
o@immerda.ch
Browse files
random name picker feature
parent
02c1c118
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
app/assets/javascripts/random.js
0 → 100644
View file @
fe03ab20
Array
.
prototype
.
sample
=
function
(){
return
this
[
Math
.
floor
(
Math
.
random
()
*
this
.
length
)];
}
function
lazyLoad
()
{
var
tag
=
document
.
createElement
(
'
script
'
);
tag
.
src
=
'
/random_names.js
'
;
document
.
body
.
appendChild
(
tag
);
}
random_loaded
=
false
;
random_loading
=
false
;
function
waitForLazyLoad
(
update
)
{
if
(
random_loaded
)
{
update
();
}
else
{
if
(
random_loading
)
{
setTimeout
(
function
(){
waitForLazyLoad
(
update
)},
300
);
}
else
{
random_loading
=
true
;
lazyLoad
();
setTimeout
(
function
(){
waitForLazyLoad
(
update
)},
300
);
}
}
}
function
randomUsername
(
update
)
{
waitForLazyLoad
(
function
()
{
var
res
=
random_forenames
.
sample
().
toLowerCase
()
+
'
.
'
+
random_surnames
.
sample
().
toLowerCase
()
+
(
Math
.
random
()
*
100
).
toFixed
();
update
(
res
);
});
}
function
randomGermanProjectname
(
n
,
update
)
{
waitForLazyLoad
(
function
()
{
var
res
=
[]
for
(
var
i
=
0
;
i
<
n
;
i
++
)
{
var
r
=
random_german_words
.
sample
().
toLowerCase
();
if
(
r
.
match
(
/
[^\w]
+/g
))
i
--
;
else
res
.
push
(
r
);
}
update
(
res
.
join
(
"
-
"
));
});
}
function
randomProjectname
(
n
,
update
)
{
waitForLazyLoad
(
function
()
{
var
res
=
[]
for
(
var
i
=
0
;
i
<
n
;
i
++
)
{
var
r
=
random_english_words
.
sample
().
toLowerCase
();
if
(
r
.
match
(
/
[^\w]
+/g
))
i
--
;
else
res
.
push
(
r
);
}
update
(
res
.
join
(
"
-
"
));
});
}
app/assets/javascripts/resources.js
0 → 100644
View file @
fe03ab20
//= require 'random'
app/assets/javascripts/signup.js
View file @
fe03ab20
...
...
@@ -2,3 +2,4 @@
//= require signup_helpers
//= require pwhelp
//= require qrtoggle.js
//= require random
app/views/application/_random.html.erb
0 → 100644
View file @
fe03ab20
<div
style=
"display:inline; padding-left: 150px; font-size: 70%"
%
>
<%=
select_tag
(
:radomize
,
options_for_select
([
[
t
(
:random
),
nil
],
[
t
(
:username
),
'username'
],
[
"
#{
t
(
:words
)
}
(de)"
,
'words_de'
],
[
"
#{
t
(
:words
)
}
(en)"
,
'words_en'
]
]),
onclick:
"
function update(name) {
var v = document.getElementById('data_name');
if (!v)
v = document.getElementById('email');
v.value = name;
}
var val = this.value;
if (val == 'username')
randomUsername(update);
if (val == 'words_en')
randomProjectname(3, update);
if (val == 'words_de')
randomGermanProjectname(3, update);
"
)
%>
</div>
app/views/resources/create.html.erb
View file @
fe03ab20
...
...
@@ -36,6 +36,9 @@ allowed = [q['max'].to_i - q['cur'].to_i, 0].max
<%
@resource_schema
.
each
do
|
n
,
v
|
%>
<div
class=
"form-group"
>
<%=
label_tag
n
%>
<%
if
n
==
'name'
%>
<%=
render
'random'
%>
<%
end
%>
<%=
case
v
when
Array
select_tag
(
'data_'
+
n
,
options_for_select
(
v
),
class:
'form-control'
)
...
...
app/views/signup/create.html.erb
View file @
fe03ab20
...
...
@@ -12,6 +12,7 @@
<%=
form_tag
(
"
#{
signup_path
}
/
#{
URI
::
escape
(
@token
)
}
"
,
method:
"post"
)
do
%>
<div
class=
"form-group"
>
<%=
label_tag
(
:email
,
(
t
:email
))
%>
<%=
render
'random'
%>
<%=
text_field_tag
(
:email
,
''
,
value:
@email
||
'ig'
,
autofill:
'off'
,
class:
"form-control"
)
%>
@
<%=
select_tag
:domain
,
options_for_select
(
@domains
.
map
{
|
d
|
[
d
,
d
]},
'immerda.ch'
),
class:
"form-control"
%>
...
...
config/locales/de.yml
View file @
fe03ab20
...
...
@@ -225,6 +225,9 @@ de:
other
:
"
Du
kannst
aktuell
noch
%{count}
neue
erstellen."
one
:
"
Du
kannst
aktuell
noch
eine
neue
erstellen."
random
:
zufällig
words
:
Wörter
activerecord
:
errors
:
messages
:
...
...
config/locales/en.yml
View file @
fe03ab20
...
...
@@ -226,6 +226,9 @@ en:
one
:
"
You
can
still
create
one."
other
:
"
You
can
still
create
up
to
%{count}
fresh
ones."
random
:
random
words
:
Words
activerecord
:
errors
:
messages
:
...
...
public/random_names.js
0 → 100644
View file @
fe03ab20
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment