Skip to content

Commit

Permalink
Add Announcements (#603)
Browse files Browse the repository at this point in the history
* add announcement entity

* add announcement partial and show in home page

* add template for donation

* improve buttons in announcement partials

* add close button

* add permissions and copies for announcement admin

* add necessary FormsProcessors and EntityNormalizer to use Entity instead of Model!

* add Announcement admin

* fix announcement api controller

* add slider for announcements

* add lang table and some fixes

* add Announcement Model

* change repository to use model instead of entity

* change admin controller and views to use new model

* change use of entity to model in public views of announcements

* add missing translations

* add announcements without donation to projects landing

* change to now show announcement and make it appear instead of remove it

* add announcements to channel layouts

* add announcements to blog

* change name of localStorage variable

* remove entity announcement

* update datetime of migration

* fix error on announcement admin form
  • Loading branch information
davidbeig authored Dec 4, 2024
1 parent 7a28615 commit e510fc3
Show file tree
Hide file tree
Showing 55 changed files with 1,342 additions and 77 deletions.
4 changes: 4 additions & 0 deletions Resources/permissions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ admin-module-communication: # Can access to module CommunicationAdminController
model: null
relational: null

admin-module-announcements: # Can access to module AnnouncementAdminController
model: null
relational: null

receive-test-communications: # Can receive test communications
model: null
relational: null
Expand Down
1 change: 1 addition & 0 deletions Resources/roles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ admin:
- edit-any-matcher # View any editing matcher
- remove-any-matcher # Remove any matcher
- admin-module-channels # Can access to channels admin modules
- admin-module-announcements # Can access to announcements admin modules
level: 70

superadmin:
Expand Down
18 changes: 10 additions & 8 deletions Resources/templates/default/channel/layout.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php

$channel=$this->channel;
$channel = $this->channel;

$this->layout("layout", [
'bodyClass' => 'channel home',
'title' => $this->text('regular-channel').' '.$channel->name,
'title' => $this->text('regular-channel') . ' ' . $channel->name,
'meta_description' => $channel->description
]);
]);

$this->supply('announcements', $this->insert("partials/components/announcements"));

$this->section('content');

Expand All @@ -17,9 +19,9 @@

<div id="side">

<?php foreach ($this->side_order as $sideitem => $sideitemName) {
<?php foreach ($this->side_order as $sideitem => $sideitemName) {
echo $this->insert("channel/partials/side/$sideitem");
} ?>
} ?>
</div>

<div id="content">
Expand All @@ -32,8 +34,8 @@

<?php $this->section('footer') ?>
<script type="text/javascript">
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt
$(function(){
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt
$(function() {
$('#slides_side_sponsor').slides({
container: 'slides_container',
effect: 'fade',
Expand All @@ -43,6 +45,6 @@
pause: 1
});
});
// @license-end
// @license-end
</script>
<?php $this->append() ?>
25 changes: 25 additions & 0 deletions Resources/templates/responsive/admin/announcements/edit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

$this->layout('admin/announcements/layout');

$this->section('admin-search-box-addons');
?>
<a class="btn btn-cyan" href="/admin/announcement"><i class="fa fa-arrow-circle-left"></i> <?= $this->text('admin-back-list') ?></a>

<?php $this->replace() ?>

<?php $this->section('admin-container-body') ?>

<?php
$id = $this->announcement->id;
?>

<h4 class="title"><?= $id ? $this->text('admin-announcement-edit', "#{$id}") : $this->text('admin-announcement-add') ?></h4>


<?= $this->form_form($this->raw('form')) ?>

</div>
</div>

<?php $this->replace() ?>
14 changes: 14 additions & 0 deletions Resources/templates/responsive/admin/announcements/layout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

$this->layout('admin/container');

$this->section('admin-container-head');

?>
<h2><?= $this->text('admin-announcements') ?></h2>

<?= $this->insert('admin/partials/search_box') ?>

<?= $this->supply('admin-announcements-head') ?>

<?php $this->replace() ?>
20 changes: 20 additions & 0 deletions Resources/templates/responsive/admin/announcements/list.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

$this->layout('admin/announcements/layout');

$this->section('admin-search-box-addons');
?>
<a class="btn btn-cyan" href="/admin/announcement/add"><i class="fa fa-plus"></i> <?= $this->text('admin-announcement-add') ?></a>

<?php $this->replace() ?>

<?php $this->section('admin-container-body') ?>

<h5><?= $this->text('admin-list-total', $this->total) ?></h5>

<?= $this->insert('admin/partials/material_table', ['list' => $this->model_list_entries($this->list, ['id', 'title', 'type', 'active', 'actions'])]) ?>

</div>
</div>

<?php $this->replace() ?>
2 changes: 2 additions & 0 deletions Resources/templates/responsive/blog/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

$this->section('content');

$this->supply('announcements', $this->insert("partials/components/announcements"));

?>

<div class="blog">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

<script type="text/javascript" src="<?= SRC_URL ?>/assets/js/channel/stories.js"></script>
<script type="text/javascript" src="<?= SRC_URL ?>/assets/js/channel/call.js"></script>

<script type="text/javascript" src="<?= SRC_URL ?>/assets/js/components/announcements.js"></script>
1 change: 1 addition & 0 deletions Resources/templates/responsive/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@

<?= $this->supply('header', $this->insert("partials/header")) ?>
<?= $this->supply('search', $this->insert("partials/search")) ?>
<?= $this->supply('announcements', $this->insert("partials/components/announcements")) ?>

<div class="page-wrap">
<?= $this->supply('sidebar', $this->insert("partials/sidebar", ['sidebarMenu' => $sidebar])) ?>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
$announcements = $this->announcements;
if ($announcements) :


$id = md5(serialize($announcements));
?>
<div class="announcement" id="<?= $id ?>">
<button id="announcement-close" class="close" aria-label="Close" onclick="this.parentNode.style.display='none'"><i class="fa fa-close"></i></button>

<div class="container">
<div class="slider-announcements">
<?php foreach ($announcements as $announcement) : ?>
<div class="row">
<div class="col-lg-8 col-md-7 col-md-offset-1 col-sm-offset-2 col-sm-6 col-xs-offset-3 col-xs-9">
<h2 class="announcement-title"><?= $announcement->title ?></h2>
<p class="announcement-description"><?= $announcement->description ?></p>
</div>
<div class="cta col-lg-4 col-md-4 col-sm-4 col-xs-12">
<?php $type = $announcement->type ?>
<?= $this->insert("partials/components/announcements/partials/$type", ['announcement' => $announcement]) ?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
<?php endif; ?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php $announcement = $this->announcement; ?>

<div class="grid-donation">
<a href="/donate/payment?amount=5" class="btn btn-lg btn-white"><?= $this->get_currency() ?> 5</a>
<a href="/donate/payment?amount=10" class="btn btn-lg btn-white"><?= $this->get_currency() ?> 10</a>
<a href="/donate/payment?amount=20" class="btn btn-lg btn-white"><?= $this->get_currency() ?> 20</a>
<a href="/donate/payment?amount=50" class="btn btn-lg btn-white"><?= $this->get_currency() ?> 50</a>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php $announcement = $this->announcement; ?>

<a href="<?= $announcement->cta_url ?>" class="btn btn-white btn-lg btn-block"><?= $announcement->cta_text ?></a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php $announcement = $this->announcement; ?>

<a href="<?= $announcement->cta_url ?>" class="btn btn-white btn-lg btn-block"><?= $announcement->cta_text ?></a>
1 change: 1 addition & 0 deletions Resources/templates/responsive/project/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
echo $this->insert('project/widgets/micro', ['project' => $project, 'admin' => $this->admin]);
$this->replace();

$this->supply('announcements', $this->insert("partials/components/announcements"));

$this->section('content');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<!-- build:js assets/js/project.js -->
<script src="<?= SRC_URL ?>/assets/vendor/slick-carousel/slick/slick.min.js"></script>
<script type="text/javascript" src="<?= SRC_URL ?>/assets/js/project/project.js"></script>
<!-- endbuild -->
<script type="text/javascript" src="<?= SRC_URL ?>/assets/js/components/announcements.js"></script>
<!-- endbuild -->
78 changes: 78 additions & 0 deletions db/migrations/20240920152538_goteo_announcement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

/**
* Migration Task class.
*/
class GoteoAnnouncement
{
public function preUp()
{
// add the pre-migration code here
}

public function postUp()
{
// add the post-migration code here
}

public function preDown()
{
// add the pre-migration code here
}

public function postDown()
{
// add the post-migration code here
}

/**
* Return the SQL statements for the Up migration
*
* @return string The SQL string to execute for the Up migration.
*/
public function getUpSQL()
{
return "
CREATE TABLE `announcement` (
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`title` TEXT NOT NULL,
`description` TEXT NOT NULL,
`type` VARCHAR(50) NOT NULL,
`lang` VARCHAR(6) NOT NULL,
`project_id` VARCHAR(50) COLLATE utf8_general_ci DEFAULT NULL,
`cta_url` VARCHAR(255),
`cta_text` VARCHAR(255),
`active` INT(1) NOT NULL DEFAULT 0,
`start_date` date NULL,
`end_date` date NULL,
`created_at` timestamp NOT NULL DEFAULT current_timestamp,
`modified_at` timestamp NOT NULL DEFAULT current_timestamp on update CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
FOREIGN KEY (`project_id`) REFERENCES `project` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE `announcement_lang` (
`id` BIGINT(20) UNSIGNED NOT NULL,
`title` TEXT NOT NULL,
`description` TEXT NOT NULL,
`lang` VARCHAR(6) NOT NULL,
`cta_url` VARCHAR(255),
`cta_text` VARCHAR(255),
FOREIGN KEY (`id`) REFERENCES `announcement` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
);
";
}

/**
* Return the SQL statements for the Down migration
*
* @return string The SQL string to execute for the Down migration.
*/
public function getDownSQL()
{
return "
DROP TABLE `announcement_lang`;
DROP TABLE `announcement`;
";
}
}
60 changes: 60 additions & 0 deletions public/assets/js/components/announcements.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
@licstart The following is the entire license notice for the
JavaScript code in this page.
Copyright (C) 2010 Goteo Foundation
The JavaScript code in this page is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
@licend The above is the entire license notice
for the JavaScript code in this page.
*/

$(function() {
const $closeAnnouncement = document.getElementById('announcement-close');
const $announcements = $closeAnnouncement.parentNode;
const announcementsId = $announcements.id;
const date = new Date();
const today = `${date.getFullYear()}-${date.getMonth()}-${date.getDay()}`;
const itemId = `goteo_announcements_${today}_${announcementsId}`;

$closeAnnouncement.addEventListener("click", (event) => {
$announcements.style.display = 'none';
localStorage.setItem(itemId, true);
});

if (!localStorage.getItem(itemId))
$announcements.style.display = 'block';

$(".slider-announcements").slick({
dots: false,
infinite: true,
autoplay: false,
autoplaySpeed: 7000,
speed: 500,
fade: true,
cssEase: "linear",
responsive: [
{
breakpoint: 500,
settings: {
dots: true,
arrows: false
}
}
]
});
});
1 change: 1 addition & 0 deletions public/assets/sass/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
@import 'components/values';
@import 'components/workshops_slider';
@import 'components/dataset';
@import 'components/announcement';

@import 'misc/misc';
@import 'misc/charts';
Expand Down
Loading

0 comments on commit e510fc3

Please sign in to comment.