Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
js: repositories remaining refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
vitoravelino committed Jul 26, 2017
1 parent 84472e1 commit ad5da31
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 43 deletions.
1 change: 0 additions & 1 deletion app/assets/javascripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import './vue-shared';
// Require tree.
// NOTE: This should be moved into proper modules.
import './bootstrap';
import './repositories';
import './teams';

// new modules structure
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import BaseComponent from '~/base/component';

const COMMENT_BODY = '#comment_body';

class CommentForm extends BaseComponent {
elements() {
this.$commentBody = this.$el.find(COMMENT_BODY);
}

toggle() {
this.$el.toggle(400, 'swing', () => {
const visible = this.$el.is(':visible');

if (visible) {
this.$commentBody.focus();
}

layout_resizer();
});
}
}

export default CommentForm;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import BaseComponent from '~/base/component';

import CommentForm from '../components/comment-form';

class CommentsPanel extends BaseComponent {
elements() {
this.$toggle = this.$el.find('.add-comment');
this.$commentForm = this.$el.find('.comment-form');
}

events() {
this.$toggle.on('click', () => this.toggle());
}

mount() {
this.form = new CommentForm(this.$commentForm);
}

toggle() {
this.form.toggle();
}
}

export default CommentsPanel;
3 changes: 3 additions & 0 deletions app/assets/javascripts/modules/repositories/pages/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import EventBus from '~/utils/eventbus';
import TagsTable from '../components/tags-table';
import TagsNotLoaded from '../components/tags-not-loaded';
import DeleteTagAction from '../components/delete-tag-action';
import CommentsPanel from '../components/comments-panel';

import RepositoriesService from '../services/repositories';
import TagsService from '../services/tags';
Expand Down Expand Up @@ -125,6 +126,8 @@ $(() => {
set(this, 'isLoading', true);
this.loadData();
EventBus.$on('deleteTags', () => this.deleteTags());
// eslint-disable-next-line no-new
new CommentsPanel($('.comments-wrapper'));
},
});
});
2 changes: 1 addition & 1 deletion app/assets/stylesheets/pages/repositories.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@import "comments";

#write_comment_repository_btn {
.add-comment {
padding-top: 0px;
padding-bottom: 0px;
border: 0px;
Expand Down
67 changes: 34 additions & 33 deletions app/views/repositories/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -60,38 +60,39 @@
<tags-not-loaded v-if="notLoaded"></tags-not-loaded>
<tags-table v-if="!isLoading && !notLoaded" :tags="tags" :can-destroy="#{can_destroy?(@repository)}" :state="state" :security-enabled="#{security_vulns_enabled?}"></tags-table>

#write_comment_form.collapse
= form_for [@repository, @repository.comments.build], remote: true, html: {id: 'new-comment-form', class: 'form-horizontal', role: 'form'} do |f|
.form-group
= f.label :comment, {class: 'control-label col-md-2'}
.col-md-7
= f.text_area(:body, class: 'form-control fixed-size', required: false, placeholder: "Please write a comment.")
.form-group
.col-md-offset-2.col-md-7
= f.submit('Add', class: 'btn btn-primary')
.comments-wrapper
.comment-form.collapse
= form_for [@repository, @repository.comments.build], remote: true, html: {id: 'new-comment-form', class: 'form-horizontal', role: 'form'} do |f|
.form-group
= f.label :comment, {class: 'control-label col-md-2'}
.col-md-7
= f.text_area(:body, class: 'form-control fixed-size', required: false, placeholder: "Please write a comment.")
.form-group
.col-md-offset-2.col-md-7
= f.submit('Add', class: 'btn btn-primary')

.panel.panel-default
.panel-heading.clearfix
.row
.col-sm-6
h5
span class="number_of_comments badge"
= @repository.comments.count
span class="comment_string"
- if @repository.comments.count == 1
| Comment
- else
| Comments
.col-sm-6.text-right
a#write_comment_repository_btn.btn.btn-xs.btn-link.js-toggle-button role="button"
i.fa.fa-comment
| Write a comment
.panel.panel-default
.panel-heading.clearfix
.row
.col-sm-6
h5
span class="number_of_comments badge"
= @repository.comments.count
span class="comment_string"
- if @repository.comments.count == 1
| Comment
- else
| Comments
.col-sm-6.text-right
a.btn.btn-xs.btn-link.add-comment role="button"
i.fa.fa-comment
| Write a comment

#comments.panel-body.panel-no-side-padding
.container-full
- if @repository_comments.empty?
.no-comments-found
' Nobody has left a comment yet.
- else
- @repository_comments.each do |comment|
= render(comment)
#comments.panel-body.panel-no-side-padding
.container-full
- if @repository_comments.empty?
.no-comments-found
' Nobody has left a comment yet.
- else
- @repository_comments.each do |comment|
= render(comment)
16 changes: 8 additions & 8 deletions spec/features/repositories_comments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@

expect(page).to have_content("Nobody has left a comment")

find("#write_comment_repository_btn").click
wait_for_effect_on("#write_comment_form")
find(".add-comment").click
wait_for_effect_on(".comment-form")

fill_in "comment[body]", with: "Something"
click_button "Add"
Expand All @@ -55,8 +55,8 @@

expect(page).to have_content("Nobody has left a comment")

find("#write_comment_repository_btn").click
wait_for_effect_on("#write_comment_form")
find(".add-comment").click
wait_for_effect_on(".comment-form")

fill_in "comment[body]", with: "Something"
click_button "Add"
Expand All @@ -72,8 +72,8 @@

expect(page).to have_content("Nobody has left a comment")

find("#write_comment_repository_btn").click
wait_for_effect_on("#write_comment_form")
find(".add-comment").click
wait_for_effect_on(".comment-form")

fill_in "comment[body]", with: "Something"
click_button "Add"
Expand All @@ -92,8 +92,8 @@
scenario "An user cannot comment an empty text", js: true do
visit repository_path(visible_repository)

find("#write_comment_repository_btn").click
wait_for_effect_on("#write_comment_form")
find(".add-comment").click
wait_for_effect_on(".comment-form")

click_button "Add"
wait_for_ajax
Expand Down

0 comments on commit ad5da31

Please sign in to comment.