Skip to content

Commit

Permalink
Merge branch 'main' into playwright-e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
vidya-ram committed Feb 8, 2024
2 parents 25520ff + 545660c commit f6ed21b
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 8 deletions.
19 changes: 19 additions & 0 deletions funnel/assets/js/update.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import Vue from 'vue/dist/vue.min';
import VS2 from 'vue-script2';
import toastr from 'toastr';
import Utils from './utils/helper';
import ScrollHelper from './utils/scrollhelper';
import getTimeago from './utils/get_timeago';
import { userAvatarUI, faSvg, shareDropdown } from './utils/vue_util';
import Form from './utils/formhelper';

const Updates = {
init({
Expand Down Expand Up @@ -45,6 +47,23 @@ const Updates = {
this.setReadMore = action;
this.truncated = action;
},
getCsrfToken() {
return $('meta[name="csrf-token"]').attr('content');
},
handlePinEvent(event, formId, postUrl) {
event.preventDefault();
const onSuccess = (response) => {
this.update.is_pinned = !this.update.is_pinned;
Form.updateFormNonce(response);
};

const onError = (error) => {
const errorMsg = Form.handleAjaxError(error);
toastr.error(errorMsg);
};

Form.ajaxFormSubmit(formId, postUrl, onSuccess, onError, {});
},
},
computed: {
age() {
Expand Down
12 changes: 12 additions & 0 deletions funnel/assets/sass/pages/update.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
margin: $mui-grid-padding * 0.5 0;
position: relative;

.update__heading {
.update__heading__unpin {
display: none;
}
}

.update__content {
display: inline-block;
width: 100%;
Expand All @@ -47,6 +53,12 @@
}
}

.update:hover {
.update__heading__unpin {
display: inline-block;
}
}

.update--border {
padding: $mui-grid-padding * 0.5 $mui-grid-padding 0;
border-radius: 4px;
Expand Down
3 changes: 2 additions & 1 deletion funnel/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
TicketParticipantForm,
TicketTypeForm,
)
from .update import UpdateForm
from .update import UpdateForm, UpdatePinForm
from .venue import VenueForm, VenuePrimaryForm, VenueRoomForm

__all__ = [
Expand Down Expand Up @@ -214,6 +214,7 @@
"TicketTypeForm",
"UnsubscribeForm",
"UpdateForm",
"UpdatePinForm",
"UserPermissionAssignForm",
"UsernameAvailableForm",
"VenueForm",
Expand Down
11 changes: 10 additions & 1 deletion funnel/forms/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from ..models import Update

__all__ = ['UpdateForm']
__all__ = ['UpdateForm', 'UpdatePinForm']


@Update.forms('main')
Expand All @@ -29,3 +29,12 @@ class UpdateForm(forms.Form):
is_restricted = forms.BooleanField(
__("Limit access to current participants only"), default=False
)


@Update.forms('pin')
class UpdatePinForm(forms.Form):
"""Pin an update in a project."""

is_pinned = forms.BooleanField(
__("Pin this update above other updates"), default=False
)
18 changes: 16 additions & 2 deletions funnel/templates/js/update.js.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,28 @@
<div class="page-card__card">
<div class="flex-wrapper flex-wrapper--center flex-wrapper--space-between">
<div class="update__heading">
<ul class="bullet-separated-list--flex mui--text-light mui--text-body2 update__date" v-if="update.number">
<form v-if="iseditor" :id="'pin-form-' + update.uuid_b58" :action="update.urls.edit" method="post" style="display: inline;">
<input type="hidden" :value=getCsrfToken() name="csrf_token">
<input type="hidden" value="pin" name="form.id">
<input type="hidden" v-if="!update.is_pinned" name="is_pinned" value="true">
<input type="hidden" v-if="update.is_pinned" name="is_pinned" value="">
</form>
<ul class="bullet-separated-list--flex mui--text-light mui--text-body2" v-if="update.number">
<li><a class="text-uppercase mui--text-light nounderline" :href="update.urls.view">{{ gettext('Update') }} #{{ update.number }}</a></li>
<li v-if="age"><a class="mui--text-light nounderline" :href="update.urls.view">{{ age }}</a></li>
<li v-if="update.visibility_label == 'Restricted'">
<faicon :icon="'lock-alt'"></faicon>
</li>
<li v-if="update.is_pinned">
<faicon :icon="'thumbtack'" :baseline=false :css_class="'mui--align-middle'"></faicon>
<a v-if="iseditor" href="#" @click="handlePinEvent($event, `pin-form-${update.uuid_b58}`, update.urls.edit);">
<faicon :icon="'thumbtack-solid'" :baseline=false :css_class="'mui--align-middle'"></faicon>
</a>
<faicon v-else :icon="'thumbtack-solid'" :baseline=false :css_class="'mui--align-middle'"></faicon>
</li>
<li v-if="!update.is_pinned && iseditor">
<a href="#" @click="handlePinEvent($event, `pin-form-${update.uuid_b58}`, update.urls.edit);" class="update__heading__unpin">
<faicon :icon="'thumbtack'" :baseline=false :css_class="'mui--align-middle'"></faicon>
</a>
</li>
</ul>
<p v-else class="text-capitalize mui--text-light zero-bottom-margin">{{ gettext('Draft') }}</p>
Expand Down
22 changes: 18 additions & 4 deletions funnel/views/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from flask import abort, flash
from flask import abort, flash, request

from baseframe import _, forms
from baseframe.forms import render_form
Expand All @@ -18,7 +18,7 @@

from .. import app
from ..auth import current_auth
from ..forms import SavedProjectForm, UpdateForm
from ..forms import SavedProjectForm, UpdateForm, UpdatePinForm
from ..models import Account, NewUpdateNotification, Project, Update, db
from ..typing import ReturnRenderWith, ReturnView
from .helpers import html_in_json, render_redirect
Expand Down Expand Up @@ -139,13 +139,27 @@ def publish(self) -> ReturnView:
@route('edit', methods=['GET', 'POST'])
@requires_roles({'editor'})
def edit(self) -> ReturnView:
form = UpdateForm(obj=self.obj)
if request.form.get('form.id') == 'pin':
form = UpdatePinForm(obj=self.obj)
else:
form = UpdateForm(obj=self.obj)
if form.validate_on_submit():
form.populate_obj(self.obj)
db.session.commit()
if request.form.get('form.id') == 'pin':
return {'status': 'ok', 'is_pinned': self.obj.is_pinned}
flash(_("The update has been edited"), 'success')
return render_redirect(self.obj.url_for())

if request.form.get('form.id') == 'pin':
return (
{
'status': 'error',
'error': 'pin_form_invalid',
'error_description': _("This page timed out. Reload and try again"),
'form_nonce': form.form_nonce.data,
},
400,
)
return render_form(
form=form,
title=_("Edit update"),
Expand Down

0 comments on commit f6ed21b

Please sign in to comment.