Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
3c5d1e6d
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3c5d1e6d
编写于
3月 28, 2017
作者:
F
Filipa Lacerda
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'user-callout-refactor' into 'master'
Refactored the user callout class Closes #29955 See merge request !10213
上级
62b70829
3eedb2ae
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
87 addition
and
77 deletion
+87
-77
app/assets/javascripts/user_callout.js
app/assets/javascripts/user_callout.js
+6
-37
app/helpers/application_helper.rb
app/helpers/application_helper.rb
+4
-0
app/views/dashboard/projects/index.html.haml
app/views/dashboard/projects/index.html.haml
+3
-1
app/views/shared/_user_callout.html.haml
app/views/shared/_user_callout.html.haml
+14
-0
app/views/users/show.html.haml
app/views/users/show.html.haml
+2
-2
spec/features/user_callout_spec.rb
spec/features/user_callout_spec.rb
+15
-3
spec/javascripts/fixtures/dashboard.rb
spec/javascripts/fixtures/dashboard.rb
+31
-0
spec/javascripts/fixtures/user_callout.html.haml
spec/javascripts/fixtures/user_callout.html.haml
+0
-2
spec/javascripts/user_callout_spec.js
spec/javascripts/user_callout_spec.js
+12
-32
未找到文件。
app/assets/javascripts/user_callout.js
浏览文件 @
3c5d1e6d
import
Cookies
from
'
js-cookie
'
;
const
userCalloutElementName
=
'
.user-callout
'
;
const
closeButton
=
'
.close-user-callout
'
;
const
userCalloutBtn
=
'
.user-callout-btn
'
;
const
userCalloutSvgAttrName
=
'
callout-svg
'
;
const
USER_CALLOUT_COOKIE
=
'
user_callout_dismissed
'
;
const
USER_CALLOUT_TEMPLATE
=
`
<div class="bordered-box landing content-block">
<button class="btn btn-default close close-user-callout" type="button">
<i class="fa fa-times dismiss-icon"></i>
</button>
<div class="row">
<div class="col-sm-3 col-xs-12 svg-container">
</div>
<div class="col-sm-8 col-xs-12 inner-content">
<h4>
Customize your experience
</h4>
<p>
Change syntax themes, default project pages, and more in preferences.
</p>
<a class="btn user-callout-btn" href="/profile/preferences">Check it out</a>
</div>
</div>
</div>`
;
export
default
class
UserCallout
{
constructor
()
{
this
.
isCalloutDismissed
=
Cookies
.
get
(
USER_CALLOUT_COOKIE
);
this
.
userCalloutBody
=
$
(
userCalloutElementName
);
this
.
userCalloutSvg
=
$
(
userCalloutElementName
).
attr
(
userCalloutSvgAttrName
);
$
(
userCalloutElementName
).
removeAttr
(
userCalloutSvgAttrName
);
this
.
userCalloutBody
=
$
(
'
.user-callout
'
);
this
.
init
();
}
init
()
{
const
$template
=
$
(
USER_CALLOUT_TEMPLATE
);
if
(
!
this
.
isCalloutDismissed
||
this
.
isCalloutDismissed
===
'
false
'
)
{
$template
.
find
(
'
.svg-container
'
).
append
(
this
.
userCalloutSvg
);
this
.
userCalloutBody
.
append
(
$template
);
$template
.
find
(
closeButton
).
on
(
'
click
'
,
e
=>
this
.
dismissCallout
(
e
));
$template
.
find
(
userCalloutBtn
).
on
(
'
click
'
,
e
=>
this
.
dismissCallout
(
e
));
}
else
{
this
.
userCalloutBody
.
remove
();
$
(
'
.js-close-callout
'
).
on
(
'
click
'
,
e
=>
this
.
dismissCallout
(
e
));
}
}
dismissCallout
(
e
)
{
Cookies
.
set
(
USER_CALLOUT_COOKIE
,
'
true
'
);
const
$currentTarget
=
$
(
e
.
currentTarget
);
if
(
$currentTarget
.
hasClass
(
'
close-user-callout
'
))
{
Cookies
.
set
(
USER_CALLOUT_COOKIE
,
'
true
'
);
if
(
$currentTarget
.
hasClass
(
'
close
'
))
{
this
.
userCalloutBody
.
remove
();
}
}
...
...
app/helpers/application_helper.rb
浏览文件 @
3c5d1e6d
...
...
@@ -306,4 +306,8 @@ module ApplicationHelper
def
active_when
(
condition
)
'active'
if
condition
end
def
show_user_callout?
cookies
[
:user_callout_dismissed
]
==
'true'
end
end
app/views/dashboard/projects/index.html.haml
浏览文件 @
3c5d1e6d
...
...
@@ -4,7 +4,9 @@
-
page_title
"Projects"
-
header_title
"Projects"
,
dashboard_projects_path
.user-callout
{
'callout-svg'
=>
custom_icon
(
'icon_customization'
)
}
-
unless
show_user_callout?
=
render
'shared/user_callout'
-
if
@projects
.
any?
||
params
[
:name
]
=
render
'dashboard/projects_head'
...
...
app/views/shared/_user_callout.html.haml
0 → 100644
浏览文件 @
3c5d1e6d
.user-callout
.bordered-box.landing.content-block
%button
.btn.btn-default.close.js-close-callout
{
type:
'button'
,
'aria-label'
=>
'Dismiss customize experience box'
}
=
icon
(
'times'
,
class:
'dismiss-icon'
,
'aria-hidden'
=>
'true'
)
.row
.col-sm-3.col-xs-12.svg-container
=
custom_icon
(
'icon_customization'
)
.col-sm-8.col-xs-12.inner-content
%h4
Customize your experience
%p
Change syntax themes, default project pages, and more in preferences.
=
link_to
'Check it out'
,
profile_preferences_path
,
class:
'btn btn-default js-close-callout'
app/views/users/show.html.haml
浏览文件 @
3c5d1e6d
...
...
@@ -97,8 +97,8 @@
Snippets
%div
{
class:
container_class
}
-
if
@user
==
current_user
.user-callout
{
'callout-svg'
=>
custom_icon
(
'icon_customization'
)
}
-
if
@user
==
current_user
&&
!
show_user_callout?
=
render
'shared/user_callout'
.tab-content
#activity
.tab-pane
.row-content-block.calender-block.white.second-block.hidden-xs
...
...
spec/features/user_callout_spec.rb
浏览文件 @
3c5d1e6d
...
...
@@ -7,15 +7,27 @@ describe 'User Callouts', js: true do
before
do
login_as
(
user
)
project
.
team
<<
[
user
,
:master
]
project
.
team
<<
[
user
,
:master
]
end
it
'takes you to the profile preferences when the link is clicked'
do
it
'takes you to the profile preferences when the link is clicked'
do
visit
dashboard_projects_path
click_link
'Check it out'
expect
(
current_path
).
to
eq
profile_preferences_path
end
it
'does not show when cookie is set'
do
visit
dashboard_projects_path
within
(
'.user-callout'
)
do
find
(
'.close'
).
click
end
visit
dashboard_projects_path
expect
(
page
).
not_to
have_selector
(
'.user-callout'
)
end
describe
'user callout should appear in two routes'
do
it
'shows up on the user profile'
do
visit
user_path
(
user
)
...
...
@@ -31,7 +43,7 @@ describe 'User Callouts', js: true do
it
'hides the user callout when click on the dismiss icon'
do
visit
user_path
(
user
)
within
(
'.user-callout'
)
do
find
(
'.close
-user-callout
'
).
click
find
(
'.close'
).
click
end
expect
(
page
).
not_to
have_selector
(
'.user-callout'
)
end
...
...
spec/javascripts/fixtures/dashboard.rb
0 → 100644
浏览文件 @
3c5d1e6d
require
'spec_helper'
describe
Dashboard
::
ProjectsController
,
'(JavaScript fixtures)'
,
type: :controller
do
include
JavaScriptFixturesHelpers
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:namespace
)
{
create
(
:namespace
,
name:
'frontend-fixtures'
)}
let
(
:project
)
{
create
(
:project
,
namespace:
namespace
,
path:
'builds-project'
)
}
render_views
before
(
:all
)
do
clean_frontend_fixtures
(
'dashboard/'
)
end
before
(
:each
)
do
sign_in
(
admin
)
end
it
'dashboard/user-callout.html.raw'
do
|
example
|
rendered
=
render_template
(
'shared/_user_callout'
)
store_frontend_fixture
(
rendered
,
example
.
description
)
end
private
def
render_template
(
template_file_name
)
controller
.
prepend_view_path
(
JavaScriptFixturesHelpers
::
FIXTURE_PATH
)
controller
.
render_to_string
(
template_file_name
,
layout:
false
)
end
end
spec/javascripts/fixtures/user_callout.html.haml
已删除
100644 → 0
浏览文件 @
62b70829
.user-callout
{
'callout-svg'
=>
custom_icon
(
'icon_customization'
)
}
spec/javascripts/user_callout_spec.js
浏览文件 @
3c5d1e6d
...
...
@@ -4,7 +4,7 @@ import UserCallout from '~/user_callout';
const
USER_CALLOUT_COOKIE
=
'
user_callout_dismissed
'
;
describe
(
'
UserCallout
'
,
function
()
{
const
fixtureName
=
'
static/user_
callout.html.raw
'
;
const
fixtureName
=
'
dashboard/user-
callout.html.raw
'
;
preloadFixtures
(
fixtureName
);
beforeEach
(()
=>
{
...
...
@@ -12,26 +12,22 @@ describe('UserCallout', function () {
Cookies
.
remove
(
USER_CALLOUT_COOKIE
);
this
.
userCallout
=
new
UserCallout
();
this
.
closeButton
=
$
(
'
.
close-user-callout
'
);
this
.
userCalloutBtn
=
$
(
'
.
user-callout-btn
'
);
this
.
closeButton
=
$
(
'
.
js-close-callout.close
'
);
this
.
userCalloutBtn
=
$
(
'
.
js-close-callout:not(.close)
'
);
this
.
userCalloutContainer
=
$
(
'
.user-callout
'
);
});
it
(
'
does not show when cookie is set not defined
'
,
()
=>
{
expect
(
Cookies
.
get
(
USER_CALLOUT_COOKIE
)).
toBeUndefined
();
expect
(
this
.
userCalloutContainer
.
is
(
'
:visible
'
)).
toBe
(
true
);
});
it
(
'
shows when cookie is set to false
'
,
()
=>
{
Cookies
.
set
(
USER_CALLOUT_COOKIE
,
'
false
'
);
expect
(
Cookies
.
get
(
USER_CALLOUT_COOKIE
)).
toBeDefined
();
expect
(
this
.
userCalloutContainer
.
is
(
'
:visible
'
)).
toBe
(
true
);
});
it
(
'
hides when user clicks on the dismiss-icon
'
,
()
=>
{
it
(
'
hides when user clicks on the dismiss-icon
'
,
(
done
)
=>
{
this
.
closeButton
.
click
();
expect
(
Cookies
.
get
(
USER_CALLOUT_COOKIE
)).
toBe
(
'
true
'
);
setTimeout
(()
=>
{
expect
(
document
.
querySelector
(
'
.user-callout
'
),
).
toBeNull
();
done
();
});
});
it
(
'
hides when user clicks on the "check it out" button
'
,
()
=>
{
...
...
@@ -39,19 +35,3 @@ describe('UserCallout', function () {
expect
(
Cookies
.
get
(
USER_CALLOUT_COOKIE
)).
toBe
(
'
true
'
);
});
});
describe
(
'
UserCallout when cookie is present
'
,
function
()
{
const
fixtureName
=
'
static/user_callout.html.raw
'
;
preloadFixtures
(
fixtureName
);
beforeEach
(()
=>
{
loadFixtures
(
fixtureName
);
Cookies
.
set
(
USER_CALLOUT_COOKIE
,
'
true
'
);
this
.
userCallout
=
new
UserCallout
();
this
.
userCalloutContainer
=
$
(
'
.user-callout
'
);
});
it
(
'
removes the DOM element
'
,
()
=>
{
expect
(
this
.
userCalloutContainer
.
length
).
toBe
(
0
);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录