diff --git a/vilya/actions/__init__.py b/vilya/actions/__init__.py new file mode 100644 index 0000000..c13cab1 --- /dev/null +++ b/vilya/actions/__init__.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- + +from ..core import Service +from .models import Action + + +class ActionService(Service): + __model__ = Action diff --git a/vilya/actions/models.py b/vilya/actions/models.py new file mode 100644 index 0000000..3851497 --- /dev/null +++ b/vilya/actions/models.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- + +from datetime import datetime +from ..core import db +from ..libs.const import ACTION_TYPES + + +class Action(db.Model): + __tablename__ = 'actions' + + id = db.Column(db.Integer(), primary_key=True) + type = db.Column(db.Integer(), default=ACTION_TYPES['comment']) + type_id = db.Column(db.Integer()) + issue_id = db.Column(db.Integer()) + creator_id = db.Column(db.Integer()) + created_at = db.Column(db.DateTime(), default=datetime.utcnow) + updated_at = db.Column(db.DateTime(), default=datetime.utcnow, onupdate=datetime.utcnow) + + @property + def comment(self): + from ..services import comments + return comments.get(id=self.type_id) + + @property + def creator(self): + from ..services import users + if not self.creator_id: + return None + return users.get(id=self.creator_id) diff --git a/vilya/comments/__init__.py b/vilya/comments/__init__.py new file mode 100644 index 0000000..8023ca4 --- /dev/null +++ b/vilya/comments/__init__.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- + +from ..core import Service +from .models import Comment + + +class CommentService(Service): + __model__ = Comment diff --git a/vilya/comments/forms.py b/vilya/comments/forms.py new file mode 100644 index 0000000..86266c9 --- /dev/null +++ b/vilya/comments/forms.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- + +from flask_wtf import Form +from wtforms import TextField +from wtforms.validators import DataRequired as Required + +__all__ = ['NewCommentForm', 'UpdateCommentForm'] + + +class NewCommentForm(Form): + description = TextField('Description', validators=[Required()]) + + +class UpdateCommentForm(Form): + description = TextField('Description', validators=[Required()]) diff --git a/vilya/comments/models.py b/vilya/comments/models.py new file mode 100644 index 0000000..968ebed --- /dev/null +++ b/vilya/comments/models.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +from datetime import datetime +from ..core import db +from ..libs.const import COMMENT_TYPES + + +class Comment(db.Model): + __tablename__ = 'comments' + + id = db.Column(db.Integer(), primary_key=True) + type = db.Column(db.Integer(), default=COMMENT_TYPES['issue']) + description = db.Column(db.Text) + issue_id = db.Column(db.Integer()) + creator_id = db.Column(db.Integer()) + created_at = db.Column(db.DateTime(), default=datetime.utcnow) + updated_at = db.Column(db.DateTime(), default=datetime.utcnow, onupdate=datetime.utcnow) + + @property + def creator(self): + from ..services import users + if not self.creator_id: + return None + return users.get(id=self.creator_id) diff --git a/vilya/forms.py b/vilya/forms.py index 5790b8e..45feea8 100644 --- a/vilya/forms.py +++ b/vilya/forms.py @@ -3,3 +3,4 @@ from .projects.forms import * from .issues.forms import * from .pullrequests.forms import * +from .comments.forms import * diff --git a/vilya/frontend/issue.py b/vilya/frontend/issue.py index 94942bb..9a3b0fd 100644 --- a/vilya/frontend/issue.py +++ b/vilya/frontend/issue.py @@ -6,10 +6,13 @@ flash, redirect, url_for, - abort) + abort, + request, + jsonify) from flask.ext.login import current_user from ..services import projects, users, issues -from ..forms import NewIssueForm +from ..forms import NewIssueForm, NewCommentForm +from ..libs.const import ISSUE_TYPES from . import route bp = Blueprint('issue', __name__, url_prefix='///issues') @@ -38,7 +41,7 @@ def index(): context['project'] = g.project context['project_menu'] = 'Issues' project = g.project - context['issues'] = issues.find(project_id=project.id) + context['issues'] = issues.find(project_id=project.id, type=ISSUE_TYPES['default']) return render_template('issues/index.html', **context) @@ -70,12 +73,34 @@ def create(): @route(bp, '/') -def issue_index(id): +def issue(id): context = {} context['u_name'] = g.u_name context['p_name'] = g.p_name context['project'] = g.project context['project_menu'] = 'Issues' - context['issue'] = issues.first(project_id=g.project.id, - number=id) + issue = issues.first(project_id=g.project.id, + number=id, + type=ISSUE_TYPES['default']) + context['issue'] = issue + context['new_comment_form'] = NewCommentForm() + context['actions'] = issue.actions return render_template('issues/issue.html', **context) + + +@route(bp, '//comments', methods=['post']) +def issue_comment_index(id): + # TODO move to api + context = {} + context['u_name'] = g.u_name + context['p_name'] = g.p_name + issue = issues.first(project_id=g.project.id, + number=id, + type=ISSUE_TYPES['default']) + if request.method == 'POST': + form = NewCommentForm() + if form.validate_on_submit(): + comment = issue.create_comment(creator=current_user, **form.data) + return redirect(url_for('.issue', id=id, **context)) + # return jsonify(comment=comment) + return redirect(url_for('.issue', id=id, **context)) diff --git a/vilya/frontend/templates/issues/issue.html b/vilya/frontend/templates/issues/issue.html index 5396187..a435a77 100644 --- a/vilya/frontend/templates/issues/issue.html +++ b/vilya/frontend/templates/issues/issue.html @@ -1,12 +1,18 @@ {% extends "projects/base.html" %} +{% from "issues/macros/comment.html" import render_issue_actions, render_issue_new_comment, render_issue_description %} {% block sub_content %}
-
+
#{{issue.number}} {{issue.name}} -
-
-

{{issue.description}}

-
+
+
+

{{issue.description}}

+
+ {{ render_issue_description(project, issue) }} + {{ render_issue_actions(project, issue, actions) }} + {% if new_comment_form %} + {{ render_issue_new_comment(project, current_user, issue, new_comment_form) }} + {% endif %}
{% endblock %} diff --git a/vilya/frontend/templates/issues/macros/comment.html b/vilya/frontend/templates/issues/macros/comment.html new file mode 100644 index 0000000..e369c52 --- /dev/null +++ b/vilya/frontend/templates/issues/macros/comment.html @@ -0,0 +1,188 @@ +{% macro render_issue_updated_comment_form(project, issue, comment) -%} +
+
+ + + +
+ +
+ + +
+
+{%- endmacro %} + +{% macro render_issue_new_comment_form(project, issue, form) -%} +
+ {{ form.hidden_tag() }} +
+ + +
+
+ +
+
+ +
+ +
+ +
+
+
+
+
+

Nothing to preview

+
+
+
+
+
+
+
+ + +
+
+
+
+{%- endmacro %} + +{% macro render_issue_description(project, issue) -%} +
+ + {{issue.creator.name}} + +
+
+
+ +
+ +
+
+

+ the content you are editing has changed. reload the page and try again. +

+
+
+ {{issue.description}} +
+
+
sending request…
+
+
+
+ + + +
+ +
+ + +
+
+
+
+
+
+
+{%- endmacro %} + +{% macro render_issue_actions(project, issue, actions) -%} +{% for a in actions %} +{{ render_issue_comment(project, issue, a.comment) }} +{% endfor %} +{%- endmacro %} + +{% macro render_issue_comment_author_avatar(user) -%} + + {{user.name}} + +{%- endmacro %} + +{% macro render_issue_comment(project, issue, comment) -%} +
+ {{comment.creator.name}} +
+ +
+

+ the content you are editing has changed. reload the page and try again. +

+
+
+ {{comment.description}} +
+
+
sending request…
+
+ {{render_issue_updated_comment_form(project, issue, comment)}} +
+
+
+
+
+{%- endmacro %} + +{% macro render_issue_action() -%} +{%- endmacro %} + +{% macro render_issue_new_comment(project, user, issue, form) -%} +
+ + {{user.name}} + + {{render_issue_new_comment_form(project, issue, form)}} +
+{%- endmacro %} diff --git a/vilya/frontend/templates/pullrequests/macros/comment.html b/vilya/frontend/templates/pullrequests/macros/comment.html new file mode 100644 index 0000000..1e390af --- /dev/null +++ b/vilya/frontend/templates/pullrequests/macros/comment.html @@ -0,0 +1,111 @@ +{% macro render_pullrequest_description(project, pullrequest) -%} +{% set issue = pullrequest.issue %} +
+ + {{issue.creator.name}} + +
+
+
+ +
+ +
+
+

+ the content you are editing has changed. reload the page and try again. +

+
+
+ {{issue.description}} +
+
+
sending request…
+
+
+
+ + + +
+ +
+ + +
+
+
+
+
+
+
+{%- endmacro %} + +{% macro render_pull_new_comment(project, pull, current_user) -%} +{% set issue = pull.issue %} +
+ + {{current_user.name}} + +
+
+ + +
+
+ +
+
+ +
+ +
+ +
+
+
+
+
+

Nothing to preview

+
+
+
+
+
+
+
+
+
+
+
+ + +
+
+
+
+
+{%- endmacro %} diff --git a/vilya/frontend/templates/pullrequests/pull.html b/vilya/frontend/templates/pullrequests/pull.html index f05d2aa..b9e9d10 100644 --- a/vilya/frontend/templates/pullrequests/pull.html +++ b/vilya/frontend/templates/pullrequests/pull.html @@ -1,6 +1,7 @@ {% extends "projects/base.html" %} {% from "macros/diffs/patch.html" import render_patch_file %} {% from "macros/commits/commit.html" import render_commit_item %} +{% from "pullrequest/macros/comment.html" import render_pullrequest_description, render_pull_new_comment %} {% block sub_content %}
@@ -22,7 +23,7 @@

{{pullrequest.description}}

- {{ render_comment() }} + {{ render_pullrequest_description(project, pullrequest) }} {{ render_discussion_actions() }}
@@ -129,101 +130,8 @@

Merge attempt failed

-
- Xu Tao -
-
- -
-
- -
- -
- -
-
-
-
-
-

Nothing to preview

-
-
-
-
-
-
-
-
-
-
-
- - -
-
-
-
-
+ {{ render_pull_new_comment(project, pullrequest, current_user) }} {%- endmacro %} {% macro render_commits() -%} {%- endmacro %} -{% macro render_comment() -%} -
- xu tao -
-
-
- -
-
- - xtao - - commented - - - -
-
-
-

- the content you are editing has changed. reload the page and try again. -

-
-
- {{pullrequest.description}} -
-
-
sending request…
-
-
- -
- - -
-
-
-
-
-
-
-
-
-
-{%- endmacro %} - diff --git a/vilya/issues/models.py b/vilya/issues/models.py index 3772cdf..98fd21b 100644 --- a/vilya/issues/models.py +++ b/vilya/issues/models.py @@ -2,6 +2,7 @@ from datetime import datetime from ..core import db +from ..libs.const import ISSUE_TYPES class Issue(db.Model): @@ -11,9 +12,53 @@ class Issue(db.Model): name = db.Column(db.String(200)) description = db.Column(db.Text) number = db.Column(db.Integer()) + type = db.Column(db.Integer(), default=ISSUE_TYPES['default']) project_id = db.Column(db.Integer()) creator_id = db.Column(db.Integer()) closer_id = db.Column(db.Integer()) created_at = db.Column(db.DateTime(), default=datetime.utcnow) updated_at = db.Column(db.DateTime(), default=datetime.utcnow, onupdate=datetime.utcnow) closed_at = db.Column(db.DateTime()) + + @property + def creator(self): + from ..services import users + if not self.creator_id: + return None + return users.get(id=self.creator_id) + + @property + def closer(self): + from ..services import users + if not self.closer_id: + return None + return users.get(id=self.closer_id) + + @property + def actions(self): + from ..services import actions + return actions.find(issue_id=self.id) + + def create_comment(self, description, creator): + from ..services import actions, comments + comment = comments.create(description=description, + issue_id=self.id, + creator_id=creator.id) + action = actions.create(type_id=comment.id, + issue_id=self.id, + creator_id=creator.id) + return comment + + def close_issue(self, closer): + from ..services import issues + self.closer_id = closer.id + self.closed_at = datetime.utcnow() + issues.save(self) + # TODO action + + def reopen_issue(self, creator): + from ..services import issues + self.closer_id = None + self.closed_at = None + issues.save(self) + # TODO action diff --git a/vilya/libs/const.py b/vilya/libs/const.py new file mode 100644 index 0000000..e93e91c --- /dev/null +++ b/vilya/libs/const.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- + +ISSUE_TYPES = { + 'default': 1, + 'pull': 2, +} + +COMMENT_TYPES = { + 'issue': 1, + 'pullrequest': 2, + 'commit': 3, +} + +LINE_COMMENT_TYPES = { + 'commit': 1, + 'pullrequest': 2, +} + +ACTION_TYPES = { + 'close': 1, + 'merge': 2, + 'reopen': 3, + 'comment': 4, + 'line_comment': 5, +} diff --git a/vilya/pullrequests/__init__.py b/vilya/pullrequests/__init__.py index a3ac49f..8c7052e 100644 --- a/vilya/pullrequests/__init__.py +++ b/vilya/pullrequests/__init__.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from ..core import Service +from ..libs.const import ISSUE_TYPES from .models import PullRequest @@ -16,6 +17,7 @@ def create_pullrequest(self, **kwargs): name=kwargs.get('name'), description=kwargs.get('description'), creator_id=kwargs.get('creator_id'), + type=ISSUE_TYPES['pull'], ) # new pull diff --git a/vilya/services.py b/vilya/services.py index 6bdaefd..5da35c6 100644 --- a/vilya/services.py +++ b/vilya/services.py @@ -4,8 +4,12 @@ from .users import UsersService from .issues import IssuesService from .pullrequests import PullRequestService +from .comments import CommentService +from .actions import ActionService projects = ProjectsService() users = UsersService() issues = IssuesService() pullrequests = PullRequestService() +comments = CommentService() +actions = ActionService()