Commit fa280e81 authored by Eva Gächter's avatar Eva Gächter
parents c7fc7856 1c0c3bd7
...@@ -19,7 +19,7 @@ package ch.insign.cms.blocks.sliderblock; ...@@ -19,7 +19,7 @@ package ch.insign.cms.blocks.sliderblock;
import ch.insign.cms.models.AbstractBlock; import ch.insign.cms.models.AbstractBlock;
import ch.insign.cms.models.CollectionBlock; import ch.insign.cms.models.CollectionBlock;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Predicate; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import play.twirl.api.Html; import play.twirl.api.Html;
...@@ -32,15 +32,12 @@ import javax.persistence.Entity; ...@@ -32,15 +32,12 @@ import javax.persistence.Entity;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Transient; import javax.persistence.Transient;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import static com.google.common.collect.Collections2.filter;
@Entity @Entity
@Table(name = "cms_block_collection_slider") @Table(name = "cms_block_collection_slider")
@DiscriminatorValue("SliderCollectionBlock") @DiscriminatorValue("SliderCollectionBlock")
//@SecuredEntity( name = "SliderCollectionBlock", actions = { "read", "modify" })
public class SliderCollectionBlock extends CollectionBlock { public class SliderCollectionBlock extends CollectionBlock {
private final static Logger logger = LoggerFactory.getLogger(SliderCollectionBlock.class); private final static Logger logger = LoggerFactory.getLogger(SliderCollectionBlock.class);
...@@ -88,17 +85,12 @@ public class SliderCollectionBlock extends CollectionBlock { ...@@ -88,17 +85,12 @@ public class SliderCollectionBlock extends CollectionBlock {
super.save(); super.save();
} }
public List<AbstractBlock> getSubSliderSubBlocks() { public List<SliderEntryBlock> getSubSliderSubBlocks() {
Predicate<AbstractBlock> validSliderEntityBlock = new Predicate<AbstractBlock>() { return super.getSubBlocks().stream()
public boolean apply(AbstractBlock targetBlock) { .filter(entry -> SliderEntryBlock.class.isAssignableFrom(entry.getClass()))
SliderEntryBlock sliderEntryBlock = (SliderEntryBlock) targetBlock; .map(SliderEntryBlock.class::cast)
return !sliderEntryBlock.getTitle().get().equals(""); .filter(entry -> StringUtils.isNotBlank(entry.getTitle().get()))
} .collect(Collectors.toList());
};
Collection<AbstractBlock> validSubBlocks = filter(super.getSubBlocks(), validSliderEntityBlock);
return new ArrayList(validSubBlocks);
} }
public String getSliderEntryOrder() { public String getSliderEntryOrder() {
......
...@@ -5,28 +5,32 @@ ...@@ -5,28 +5,32 @@
@import scala.collection.JavaConverters.iterableAsScalaIterableConverter @import scala.collection.JavaConverters.iterableAsScalaIterableConverter
@(data: ch.insign.cms.blocks.sliderblock.SliderCollectionBlock) @(data: ch.insign.cms.blocks.sliderblock.SliderCollectionBlock)
@_blockBase(data = data, delete = true, edit = true, add = true, color = "green", name = Messages("collection.block.name"), sortableContainer = false) { @_blockBase(data = data, delete = true, edit = true, add = true, color = "green", name = Messages("collection.block.name"), sortableContainer = false) {
@if(data.getSubSliderSubBlocks != null && !data.getSubSliderSubBlocks.isEmpty) { @Some(Template.filterPermitted(data.getSubSliderSubBlocks).asScala).filter(_.nonEmpty).map { entries =>
<div id="slider-@data.getId" class="carousel slide" data-ride="carousel"> <div id="slider-@data.getId" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators"> @if(entries.size > 1) {
@Template.filterPermitted(data.getSubSliderSubBlocks).asScala.zipWithIndex.map { case (slide: SliderEntryBlock, idx) => <ol class="carousel-indicators">
<li data-target="#slider-@data.getId" data-slide-to="@idx" class="@if(Template.filterPermitted(data.getSubSliderSubBlocks).asScala.head == slide){active}"></li> @entries.zipWithIndex.map { case (slide, idx) =>
} <li data-target="#slider-@data.getId" data-slide-to="@idx" @if(entries.head == slide){class="active"}></li>
</ol> }
</ol>
}
<div class="carousel-inner"> <div class="carousel-inner">
@Template.filterPermitted(data.getSubSliderSubBlocks).asScala.map { case slide: SliderEntryBlock => @entries.map { slide =>
<div class="carousel-item @if(Template.filterPermitted(data.getSubSliderSubBlocks).asScala.head == slide){active}"> <div class="carousel-item @if(entries.head == slide){active}">
@slide.render @slide.render
</div> </div>
} }
</div> </div>
<a class="carousel-control-prev" href="#slider-@data.getId" role="button" data-slide="prev"> @if(entries.size > 1) {
<span class="carousel-control-prev-icon" aria-hidden="true"></span> <a class="carousel-control-prev" href="#slider-@data.getId" role="button" data-slide="prev">
<span class="sr-only">Previous</span> <span class="carousel-control-prev-icon" aria-hidden="true"></span>
</a> <span class="sr-only">Previous</span>
<a class="carousel-control-next" href="#slider-@data.getId" role="button" data-slide="next"> </a>
<span class="carousel-control-next-icon" aria-hidden="true"></span> <a class="carousel-control-next" href="#slider-@data.getId" role="button" data-slide="next">
<span class="sr-only">Next</span> <span class="carousel-control-next-icon" aria-hidden="true"></span>
</a> <span class="sr-only">Next</span>
</a>
}
</div> </div>
} }
} }
@(data: ch.insign.cms.blocks.sliderblock.SliderCollectionBlock, editForm: play.data.Form[ch.insign.cms.blocks.sliderblock.SliderCollectionBlock], backURL: String)
@import metronic.text @import metronic.text
@import ch.insign.cms.views.html.admin.baseBlockEdit @import ch.insign.cms.views.html.admin.baseBlockEdit
@import play.api.i18n.Messages
@import ch.insign.cms.models.Template @import ch.insign.cms.models.Template
@import ch.insign.cms.models.CMS @import ch.insign.cms.models.CMS
@import ch.insign.cms.controllers.routes.BlockController @import ch.insign.cms.controllers.routes.BlockController
@import ch.insign.cms.blocks.sliderblock.SliderEntryBlock @import ch.insign.cms.blocks.sliderblock.SliderEntryBlock
@import helper.form @import helper.form
@import ch.insign.cms.views.html.admin.deleteBlockModal @import ch.insign.cms.views.html.admin.deleteBlockModal
@import ch.insign.commons.i18n.Language
@import ch.insign.cms.blocks.sliderblock.SliderEntryBlock @import ch.insign.cms.blocks.sliderblock.SliderEntryBlock
@import ch.insign.cms.views.html.tags._ @import ch.insign.cms.views.html.tags._
@import scala.collection.JavaConverters.iterableAsScalaIterableConverter
@(
data: ch.insign.cms.blocks.sliderblock.SliderCollectionBlock,
editForm: play.data.Form[ch.insign.cms.blocks.sliderblock.SliderCollectionBlock],
backURL: String
)
@pageHeader = { @pageHeader = {
<link rel="stylesheet" type="text/css" href="@_asset("backend/navigation-overview.css")" /> <link rel="stylesheet" type="text/css" href="@_asset("backend/navigation-overview.css")" />
...@@ -23,8 +25,7 @@ ...@@ -23,8 +25,7 @@
<script src="@_asset("backend/js/blocks-sortable.js")"></script> <script src="@_asset("backend/js/blocks-sortable.js")"></script>
} }
@baseBlockEdit(data, editForm, backURL, Messages("slider.collection.block.edit.title"), pageHeader, pageFooter) {
@baseBlockEdit(data, editForm, backURL, Messages("slider.collection.block.edit.title"), pageHeader, pageFooter){
<input type="hidden" name="sliderEntryOrder" id="slider-entry-order" value="[]"> <input type="hidden" name="sliderEntryOrder" id="slider-entry-order" value="[]">
...@@ -51,48 +52,39 @@ ...@@ -51,48 +52,39 @@
</label> </label>
} }
@if(Template.filterPermitted(data.getSubBlocks).size > 0) { @Some(Template.filterPermitted(data.getSubSliderSubBlocks).asScala).filter(_.nonEmpty).map { entries =>
<div class="dd col-md-9" id="slider-entities"> <div class="dd col-md-9" id="slider-entities">
<ol class="dd-list"> <ol class="dd-list">
@for(sub <- Template.filterPermitted(data.getSubBlocks)) { @entries.map { entry =>
@Option(sub.asInstanceOf[SliderEntryBlock]).map { slider => <li class="dd-item" data-id="@entry.getId">
<li class="dd-item" data-id="@sub.getId">
<div class="dd-handle"> <div class="dd-handle">
@CMS.getConfig.frontendLanguages.filter(lang => slider.getTitle.get(lang).nonEmpty).map { lang => @CMS.getConfig.frontendLanguages.asScala.filter(lang => entry.getTitle.get(lang).nonEmpty).map { lang =>
<span class="badge badge-primary">@lang.toUpperCase</span> <span class="badge badge-primary">@lang.toUpperCase</span>
} }
@CMS.getConfig.frontendLanguages.find(lang => slider.getTitle.get(lang).nonEmpty).map { lang => @CMS.getConfig.frontendLanguages.asScala.find(lang => entry.getTitle.get(lang).nonEmpty).map { lang =>
@slider.getTitle.get(lang) @entry.getTitle.get(lang)
} }
</div> </div>
<div class="nestable-list-actions" style="display: block"> <div class="nestable-list-actions" style="display: block">
<a href="@BlockController.edit(slider.getId, request.uri)" title="@Messages("btn.edit")" class="add-edit-lang"> <a href="@BlockController.edit(entry.getId, request.uri)" title="@Messages("btn.edit")" class="add-edit-lang">
<i class="fa fa-edit"></i> <i class="fa fa-edit"></i>
</a> </a>
<a role="button" class="deleteBlock" data-deleted-block-name="@Template.blockDisplayName(entry.getClass)" data-block-id="@entry.getId"
<a role="button" class="deleteBlock" href="@BlockController.delete(entry.getId, request.uri)" title="@Messages("btn.delete")">
data-deleted-block-name="@slider.getClass.getSimpleName" data-form-id="delete-block-form-@slider.getId"
href="@BlockController.delete(slider.getId, request.uri)" title="@Messages("btn.delete")">
<i class="fa fa-trash"></i> <i class="fa fa-trash"></i>
</a> </a>
</div> </div>
</li> </li>
} }
}
</ol> </ol>
</div> </div>
} }
</div> </div>
} }
@for(sub <- Template.filterPermitted(data.getSubBlocks)) { @Template.filterPermitted(data.getSubSliderSubBlocks).asScala.map { entry =>
@form(BlockController.delete(sub.getId, request.uri()), 'id -> ("delete-block-form-" + sub.getId), 'class -> "hide") { @form(BlockController.delete(entry.getId, request.uri), 'id -> ("delete-block-form-" + entry.getId), 'class -> "hide") {
<button class="deleteBlock" @*FIXME left for the compatibility. The better approach would be to put it in the confirmation modal*@
data-deleted-block-name="@sub.getClass.getSimpleName">
<span class="glyphicon glyphicon-trash"></span>
</button>
} }
} }
......
...@@ -14,7 +14,8 @@ ...@@ -14,7 +14,8 @@
name: String = "", name: String = "",
color: String = "gray", color: String = "gray",
sortableContainer: Boolean = false, sortableContainer: Boolean = false,
CssClass: String="" )(content: Html) CssClass: String = ""
)(content: Html)
@* adds debug info in debug mode *@ @* adds debug info in debug mode *@
@withDebugInfo(content: Html) = { @withDebugInfo(content: Html) = {
@if(Template.isDebugMode()) { @if(Template.isDebugMode()) {
...@@ -27,18 +28,15 @@ ...@@ -27,18 +28,15 @@
} }
} }
@responsiveCollectionClass = @{ @responsiveCollectionClass = @{
Some(data).map{ Some(data).map {
case rc: ResponsiveCollection => rc.getResponsiveCollectionCssClass case rc: ResponsiveCollection => rc.getResponsiveCollectionCssClass
case _ => None case _ => None
} }
} }
@wrapIntoColumn(content: Html) = { @responsiveBlockClass = @{
@if(Template.addColWidthClass(data).nonEmpty) { Some(data).map(_.getParentBlock).map {
<div class="@Template.addColWidthClass(data)"> case rs: ResponsiveCollection => Template.addColWidthClass(data)
@content case _ => "container"
</div>
} else {
@content
} }
} }
@wrapIntoContainer(content: Html) = { @wrapIntoContainer(content: Html) = {
...@@ -127,7 +125,7 @@ ...@@ -127,7 +125,7 @@
</div> </div>
} else { } else {
@wrapIntoContainer { @wrapIntoContainer {
<div class="@Some(CssClass).filterNot(_.isEmpty).getOrElse("pcms-container") @Template.addColWidthClass(data) @responsiveCollectionClass"> <div class="@Some(CssClass).filterNot(_.isEmpty) @responsiveBlockClass @responsiveCollectionClass">
@content @content
</div> </div>
} }
......
@(data: ch.insign.cms.models.ContentBlock)(extension: Html=Html.apply("")) @import ch.insign.cms.views.html._blockBase
@(
@import ch.insign.cms.models.Template data: ch.insign.cms.models.ContentBlock
@import ch.insign.cms.views.html._blockBase; )(extension: Html = Html.apply(""))
@import play.api.i18n.Messages; @_blockBase(data = data, color = "red") {
<h3>@data.getTitle</h3>
@_blockBase(data = data, delete=true, edit=true, add=false, color="red", name=Messages("content.block.name"), CssClass="container") { <p>@Html(data.getContent.get)</p>
<!-- Start ContentBlock @data.getId --> @extension
<h3>@data.getTitle</h3>
<p>@{Html(data.getContent.get)}</p>
@extension
<!-- End ContentBlock @data.getId -->
} }
...@@ -8,5 +8,7 @@ ...@@ -8,5 +8,7 @@
@import ch.insign.cms.blocks.horizontalcollection.HorizontalCollectionBlock @import ch.insign.cms.blocks.horizontalcollection.HorizontalCollectionBlock
@(data: ch.insign.cms.models.PageBlock) @(data: ch.insign.cms.models.PageBlock)
@main(page = data) { @main(page = data) {
@Template.addBlockToSlot(classOf[CollectionBlock], data, "main").context("mainContext").render() <div class="content">
@Template.addBlockToSlot(classOf[CollectionBlock], data, "main").context("mainContext").render()
</div>
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment