Skip to content
This repository was archived by the owner on May 20, 2018. It is now read-only.

Commit 40260f0

Browse files
committed
Merge pull request #218 from levlaz/feature/archive
Added Archive
2 parents 80c7b0f + cc1e2d7 commit 40260f0

File tree

6 files changed

+91
-22
lines changed

6 files changed

+91
-22
lines changed

app/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,4 @@ def create_app(config_name):
4848
db.session.add(admin)
4949
db.session.commit()
5050

51-
5251
return app

app/main/views.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def index():
1616
if current_user.is_authenticated():
1717
notes = Note.query.filter_by(
1818
author_id=current_user.id,
19-
is_deleted=False).order_by(
19+
is_deleted=False, is_archived=False).order_by(
2020
Note.is_favorite.desc(),
2121
Note.updated_date.desc()).all()
2222
return render_template('app/app.html', notes=notes)
@@ -305,6 +305,35 @@ def favorite(id):
305305
return redirect(url_for('.index'))
306306

307307

308+
@main.route('/archive')
309+
@login_required
310+
def view_archive():
311+
if current_user.is_authenticated():
312+
notes = Note.query.filter_by(
313+
author_id=current_user.id,
314+
is_deleted=False, is_archived=True).order_by(
315+
Note.updated_date.desc()).all()
316+
if len(notes) == 0:
317+
flash("Archive is empty")
318+
return redirect(url_for('.index'))
319+
return render_template('app/archive.html', notes=notes)
320+
else:
321+
return render_template('index.html')
322+
323+
324+
@main.route('/archive/<int:id>')
325+
@login_required
326+
def archive(id):
327+
note = Note.query.get_or_404(id)
328+
if current_user != note.author:
329+
abort(403)
330+
else:
331+
note.is_archived = True
332+
db.session.commit()
333+
flash('The note has been archived.')
334+
return redirect(url_for('.index'))
335+
336+
308337
@main.route('/shutdown')
309338
def server_shutdown():
310339
if not current_app.testing:

app/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ class Note(db.Model):
214214
notebook_id = db.Column(db.Integer, db.ForeignKey('notebooks.id'))
215215
is_deleted = db.Column(db.Boolean, default=False)
216216
is_favorite = db.Column(db.Boolean, default=False)
217+
is_archived = db.Column(db.Boolean, default=False)
217218

218219
tags = db.relationship(
219220
"Tag", secondary=note_tag,

app/templates/app/_note.html

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{% for note in notes %}
2-
{% if request.query_string == '' and loop.index == 1 %}
3-
<div class="tab-pane active" id="{{ note.id }}">
4-
{% elif request.args.get('active_note')|int == note.id %}
5-
<div class="tab-pane active" id="{{ note.id }}">
6-
{% else %}
7-
<div class="tab-pane" id="{{ note.id }}">
8-
{% endif %}
2+
{% if request.query_string == '' and loop.index == 1 %}
3+
<div class="tab-pane active" id="{{ note.id }}">
4+
{% elif request.args.get('active_note')|int == note.id %}
5+
<div class="tab-pane active" id="{{ note.id }}">
6+
{% else %}
7+
<div class="tab-pane" id="{{ note.id }}">
8+
{% endif %}
99

1010
<h1> {{ note.title }} </h1>
1111

@@ -16,27 +16,26 @@ <h1> {{ note.title }} </h1>
1616
</div>
1717

1818
<div class="note-actions">
19-
{% if not note.is_deleted %}
20-
{% if note.is_favorite %}
21-
<a href="{{ url_for('.favorite', id=note.id) }}"><span class="favorite actions glyphicon glyphicon-star" aria-hidden="true" data-toggle="tooltip" data-placement="bottom" data-original-title="Unmark as favorite" ></a></span>
22-
{% else %}
23-
<a href="{{ url_for('.favorite', id=note.id) }}"><span class="actions glyphicon glyphicon-star" aria-hidden="true" data-toggle="tooltip" data-placement="bottom" data-original-title="Mark as favorite"></a></span>
24-
{% endif %}
25-
<a href="{{ url_for('.share', id=note.id) }}"><span class="actions glyphicon glyphicon-share" aria-hidden="true" data-toggle="tooltip" data-placement="bottom" data-original-title="Share"></a></span>
26-
<a href="{{ url_for('.edit', id=note.id) }}"><span class="actions glyphicon glyphicon-pencil" aria-hidden="true" data-toggle="tooltip" data-placement="bottom" data-original-title="Edit"></a></span>
27-
<a href="{{ url_for('.delete', id=note.id) }}"><span class="actions glyphicon glyphicon-remove" aria-hidden="true" data-toggle="tooltip" data-placement="bottom" data-original-title="Delete"></a></span>
28-
{% else %}
19+
{% if not note.is_deleted %}
20+
{% if note.is_favorite %}
21+
<a href="{{ url_for('.favorite', id=note.id) }}"><i class="fa fa-star"></i></a>
22+
{% else %}
23+
<a href="{{ url_for('.favorite', id=note.id) }}"><i class="fa fa-star-o"></i></a>
24+
{% endif %}
25+
<a href="{{ url_for('.share', id=note.id) }}"><i class="fa fa-share"></i></a>
26+
<a href="{{ url_for('.edit', id=note.id) }}"><i class="fa fa-pencil-square-o"></i></a>
27+
<a href="{{ url_for('.archive', id=note.id) }}"><i class="fa fa-archive"></i></a>
28+
<a href="{{ url_for('.delete', id=note.id) }}"><i class="fa fa-trash"></i></a>
29+
{% else %}
2930
<a href="{{ url_for('.restore', id=note.id) }}"><span class="good actions glyphicon glyphicon-check" aria-hidden="true" data-toggle="tooltip" data-placement="bottom" data-original-title="Restore"></a></span>
3031
<a href="{{ url_for('.delete_forever', id=note.id) }}"><span class="bad actions glyphicon glyphicon-remove" aria-hidden="true" data-toggle="tooltip" data-placement="bottom" data-original-title="Delete Forever"></a></span>
31-
{% endif %}
32+
{% endif %}
3233
</div>
3334

3435
<div class="note-notebook">
3536
<a class="label label-notebook" href="{{ url_for('.notebook', id=note.notebook_id) }}"> {{ note.get_notebook(note.notebook_id).title | truncate(20) }} Notebook </a>
3637
</div>
3738

38-
39-
4039
<div class="note-tags">
4140
<p>
4241
{% if current_user == note.author %}

app/templates/app/app_base.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
<li class="sidebar-item" title="Settings">
4040
<a href="/settings"><span class="nav-item glyphicon glyphicon-cog" aria-hidden="true"></span><br><span class="nav-description">Settings</span></a>
4141
</li>
42+
<li class="sidebar-item" title="Archive">
43+
<a href="/archive"><i class="fa fa-archive"></i><br><span class="nav-description">Archive</span></a>
44+
</li>
4245
<li class="sidebar-item" title="View Trash">
4346
<a href="/trash"><span class="nav-item glyphicon glyphicon-trash" aria-hidden="true"></span><br><span class="nav-description">Trash</span></a>
4447
</li>

app/templates/app/archive.html

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{% extends 'app/app_base.html' %}
2+
3+
{% block title %} Braindump | Archive {% endblock %}
4+
5+
{% block page_content %}
6+
<div class="col-sm-10">
7+
<p class="heading"> Archived Notes</p>
8+
</div>
9+
10+
<div class="row">
11+
12+
<div class="col-sm-4">
13+
<ul class="nav nav-pills nav-stacked">
14+
{% for note in notes %}
15+
{% if loop.index == 1 %}
16+
<li class="note-content active">
17+
{% else %}
18+
<li class="note-content">
19+
{% endif %}
20+
<a href="#{{ note.id }}" data-toggle="pill">
21+
22+
{{ note.title }}
23+
<br />
24+
<small>{{ moment(note.updated_date).fromNow() }}</small>
25+
</a>
26+
</li>
27+
{% endfor %}
28+
</ul>
29+
</div>
30+
31+
<div class="col-sm-7 preview">
32+
<div class="tab-content">
33+
{% include 'app/_note.html' %}
34+
</div>
35+
</div>
36+
37+
</div>
38+
{% endblock %}

0 commit comments

Comments
 (0)