Skip to content

Commit

Permalink
email별로 habit을 calendar에 출력
Browse files Browse the repository at this point in the history
  • Loading branch information
TIAHWANG committed Apr 22, 2020
1 parent d45d930 commit ccef537
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 37 deletions.
8 changes: 5 additions & 3 deletions app.py
Expand Up @@ -24,7 +24,8 @@ def listing():
if habit['email'] == current_email:
user_habit_list.append(habit)
username = current_email.split("@")[0]
return render_template("habits.html", email=username, habits=user_habit_list)

return render_template("habits.html", username=username, email=current_email, habits=user_habit_list)

@app.route('/habits', methods=['POST'])
def saving():
Expand All @@ -51,9 +52,10 @@ def listingEvents():
@app.route('/habits-date', methods=['POST'])
def savingEvents():
date_receive = request.form['date']
title_receive = request.form['title'];
title_receive = request.form['title']
email = request.form['email']

calendar = {'date': date_receive, 'title': title_receive}
calendar = {'date': date_receive, 'title': title_receive, 'email': email}
db.calendars.insert_one(calendar)

return jsonify({'result': 'success'})
Expand Down
55 changes: 21 additions & 34 deletions templates/habits.html
Expand Up @@ -6,10 +6,7 @@

<!-- Required meta tags -->
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />

<!-- JS -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
Expand All @@ -25,31 +22,15 @@
></script>

<!-- FullCalendar-Moment -->
<script
class="cssdesk"
src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.0/moment.min.js"
type="text/javascript"
></script>
<script class="cssdesk" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.0/moment.min.js" type="text/javascript"></script>

<!-- 구글폰트 -->
<link
href="https://fonts.googleapis.com/css?family=Stylish&display=swap"
rel="stylesheet"
/>
<link href="https://fonts.googleapis.com/css?family=Stylish&display=swap" rel="stylesheet" />

<!-- CSS -->
<link
rel="stylesheet"
href="{{ url_for('static', filename='css/fullcalendar.css') }}"
/>
<link
rel="stylesheet"
href="{{ url_for('static', filename='css/daygrid.css') }}"
/>
<link
rel="stylesheet"
href="{{ url_for('static', filename='css/calendar.css') }}?1=1"
/>
<link rel="stylesheet" href="{{ url_for('static', filename='css/fullcalendar.css') }}" />
<link rel="stylesheet" href="{{ url_for('static', filename='css/daygrid.css') }}" />
<link rel="stylesheet" href="{{ url_for('static', filename='css/calendar.css') }}?1=1" />

<!-- FullCalendar JS -->
<script src="{{ url_for('static', filename='js/fullcalendar.js') }}"></script>
Expand Down Expand Up @@ -82,22 +63,28 @@
droppable: true,
displayEventTime: false,
eventReceive: function (event, _) {
console.log(event);
saveEvent(event);
},
eventSources: [
{
events: function (_, successCallback, __) {
const currentEmail = location.search.split("=")[1];
$.ajax({
url: "/habits-date",
type: "GET",
dataType: "json",
data: {},
success: function (response) {
const eventsList =
response["events_list"];
const eventsList = response["events_list"];
console.log(eventsList);
successCallback(eventsList);
let event = [];
for (let i = 0; i < eventsList.length; i++) {
if (eventsList[i].email === currentEmail) {
event.push(eventsList[i]);
}
}
console.log(event);
successCallback(event);
},
});
},
Expand All @@ -109,14 +96,14 @@
});

function saveEvent(event) {
const email = location.search.split("=")[1];
$.ajax({
type: "POST",
url: "/habits-date",
url: `/habits-date`,
data: {
date: moment(event.event.start).format(
"YYYY-MM-DDThh:mm"
),
date: moment(event.event.start).format("YYYY-MM-DDThh:mm"),
title: event.event.title,
email: email,
},
dataType: "json",
success: function (response) {
Expand All @@ -132,7 +119,7 @@
</head>
<body>
<h1>Calendar</h1>
<h3>안녕하세요 {{ email }}님!</h3>
<h3>안녕하세요 {{ username }}님!</h3>
<div id="external-events">
<p>
<strong>😃 My Habits</strong>
Expand Down

0 comments on commit ccef537

Please sign in to comment.