add Language entity and UI

This commit is contained in:
amentis 2023-11-27 18:22:13 +02:00
parent 6fb601929a
commit 61218ed220
43 changed files with 2184 additions and 41 deletions

View File

@ -80,5 +80,10 @@ public class AuditableAction {
public static final EventId Tenant_Persist = new EventId(12002, "Tenant_Persist"); public static final EventId Tenant_Persist = new EventId(12002, "Tenant_Persist");
public static final EventId Tenant_Delete = new EventId(12003, "Tenant_Delete"); public static final EventId Tenant_Delete = new EventId(12003, "Tenant_Delete");
public static final EventId Language_Query = new EventId(13000, "Language_Query");
public static final EventId Language_Lookup = new EventId(13001, "Language_Lookup");
public static final EventId Language_Persist = new EventId(13002, "Language_Persist");
public static final EventId Language_Delete = new EventId(13003, "Language_Delete");
} }

View File

@ -28,6 +28,7 @@ public final class Permission {
//Language //Language
public static String BrowseLanguage = "BrowseLanguage"; public static String BrowseLanguage = "BrowseLanguage";
public static String EditLanguage = "EditLanguage"; public static String EditLanguage = "EditLanguage";
public static String DeleteLanguage = "DeleteLanguage";
//Language //Language
public static String BrowseStatistics = "BrowseStatistics"; public static String BrowseStatistics = "BrowseStatistics";

View File

@ -0,0 +1,87 @@
package eu.eudat.data;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.converters.enums.IsActiveConverter;
import jakarta.persistence.*;
import java.time.Instant;
import java.util.UUID;
@Entity
@Table(name = "\"Language\"")
public class LanguageEntity {
@Id
@Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false)
private UUID id;
public static final String _id = "id";
@Column(name = "code", length = 20, nullable = false)
private String code;
public static final String _code = "code";
@Column(name = "payload", nullable = false)
private String payload;
public static final String _payload = "payload";
@Column(name = "\"created_at\"", nullable = false)
private Instant createdAt;
public static final String _createdAt = "createdAt";
@Column(name = "\"updated_at\"", nullable = false)
private Instant updatedAt;
public static final String _updatedAt = "updatedAt";
@Column(name = "is_active", nullable = false)
@Convert(converter = IsActiveConverter.class)
private IsActive isActive;
public static final String _isActive = "isActive";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getPayload() {
return payload;
}
public void setPayload(String payload) {
this.payload = payload;
}
public Instant getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}
public Instant getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Instant updatedAt) {
this.updatedAt = updatedAt;
}
public IsActive getIsActive() {
return isActive;
}
public void setIsActive(IsActive isActive) {
this.isActive = isActive;
}
}

View File

@ -0,0 +1,86 @@
package eu.eudat.model;
import eu.eudat.commons.enums.IsActive;
import java.time.Instant;
import java.util.UUID;
public class Language {
private UUID id;
public static final String _id = "id";
private String code;
public static final String _code = "code";
private String payload;
public static final String _payload = "payload";
private Instant createdAt;
public static final String _createdAt = "createdAt";
private Instant updatedAt;
public static final String _updatedAt = "updatedAt";
private IsActive isActive;
public static final String _isActive = "isActive";
private String hash;
public final static String _hash = "hash";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getPayload() {
return payload;
}
public void setPayload(String payload) {
this.payload = payload;
}
public Instant getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}
public Instant getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Instant updatedAt) {
this.updatedAt = updatedAt;
}
public IsActive getIsActive() {
return isActive;
}
public void setIsActive(IsActive isActive) {
this.isActive = isActive;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
}

View File

@ -0,0 +1,61 @@
package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.XmlHandlingService;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.LanguageEntity;
import eu.eudat.model.Language;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class LanguageBuilder extends BaseBuilder<Language, LanguageEntity>{
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public LanguageBuilder(
ConventionService conventionService,
BuilderFactory builderFactory, QueryFactory queryFactory, XmlHandlingService xmlHandlingService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(LanguageBuilder.class)));
}
public LanguageBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<Language> build(FieldSet fields, List<LanguageEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
List<Language> models = new ArrayList<>();
for (LanguageEntity d : data) {
Language m = new Language();
if (fields.hasField(this.asIndexer(Language._id))) m.setId(d.getId());
if (fields.hasField(this.asIndexer(Language._code))) m.setCode(d.getCode());
if (fields.hasField(this.asIndexer(Language._payload))) m.setPayload(d.getPayload());
if (fields.hasField(this.asIndexer(Language._createdAt))) m.setCreatedAt(d.getCreatedAt());
if (fields.hasField(this.asIndexer(Language._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
if (fields.hasField(this.asIndexer(Language._isActive))) m.setIsActive(d.getIsActive());
if (fields.hasField(this.asIndexer(Language._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -0,0 +1,42 @@
package eu.eudat.model.censorship;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class LanguageCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(LanguageCensor.class));
protected final AuthorizationService authService;
protected final CensorFactory censorFactory;
public LanguageCensor(ConventionService conventionService,
AuthorizationService authService,
CensorFactory censorFactory) {
super(conventionService);
this.authService = authService;
this.censorFactory = censorFactory;
}
public void censor(FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeForce(Permission.BrowseLanguage);
}
}

View File

@ -0,0 +1,78 @@
package eu.eudat.model.deleter;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.LanguageEntity;
import eu.eudat.query.LanguageQuery;
import gr.cite.tools.data.deleter.Deleter;
import gr.cite.tools.data.deleter.DeleterFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import jakarta.persistence.EntityManager;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.management.InvalidApplicationException;
import java.time.Instant;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class LanguageDeleter implements Deleter {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(LanguageDeleter.class));
private final EntityManager entityManager;
protected final QueryFactory queryFactory;
protected final DeleterFactory deleterFactory;
@Autowired
public LanguageDeleter(
EntityManager entityManager,
QueryFactory queryFactory,
DeleterFactory deleterFactory
) {
this.entityManager = entityManager;
this.queryFactory = queryFactory;
this.deleterFactory = deleterFactory;
}
public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException {
logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids));
List<LanguageEntity> data = this.queryFactory.query(LanguageQuery.class).ids(ids).collect();
logger.trace("retrieved {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.deleteAndSave(data);
}
public void deleteAndSave(List<LanguageEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.delete(data);
logger.trace("saving changes");
this.entityManager.flush();
logger.trace("changes saved");
}
public void delete(List<LanguageEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
if (data == null || data.isEmpty())
return;
Instant now = Instant.now();
for (LanguageEntity item : data) {
logger.trace("deleting item {}", item.getId());
item.setIsActive(IsActive.Inactive);
item.setUpdatedAt(now);
logger.trace("updating item");
this.entityManager.merge(item);
logger.trace("updated item");
}
}
}

View File

@ -0,0 +1,56 @@
package eu.eudat.model.persist;
import eu.eudat.commons.validation.ValidId;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.util.UUID;
public class LanguagePersist {
@ValidId(message = "{validation.invalidid}")
private UUID id;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
@Size(max = 20, message = "{validation.largerthanmax}")
private String code;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String payload;
private String hash;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getPayload() {
return payload;
}
public void setPayload(String payload) {
this.payload = payload;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
}

View File

@ -0,0 +1,182 @@
package eu.eudat.query;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.LanguageEntity;
import eu.eudat.model.Language;
import gr.cite.tools.data.query.FieldResolver;
import gr.cite.tools.data.query.QueryBase;
import gr.cite.tools.data.query.QueryContext;
import jakarta.persistence.Tuple;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Predicate;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.time.Instant;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class LanguageQuery extends QueryBase<LanguageEntity> {
private String like;
private Collection<UUID> ids;
private Collection<IsActive> isActives;
private Collection<String> codes;
private Collection<UUID> excludedIds;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
public LanguageQuery like(String value) {
this.like = value;
return this;
}
public LanguageQuery ids(UUID value) {
this.ids = List.of(value);
return this;
}
public LanguageQuery ids(UUID... value) {
this.ids = Arrays.asList(value);
return this;
}
public LanguageQuery ids(Collection<UUID> values) {
this.ids = values;
return this;
}
public LanguageQuery isActive(IsActive value) {
this.isActives = List.of(value);
return this;
}
public LanguageQuery isActive(IsActive... value) {
this.isActives = Arrays.asList(value);
return this;
}
public LanguageQuery isActive(Collection<IsActive> values) {
this.isActives = values;
return this;
}
public LanguageQuery codes(String value) {
this.codes = List.of(value);
return this;
}
public LanguageQuery codes(String... value) {
this.codes = Arrays.asList(value);
return this;
}
public LanguageQuery codes(Collection<String> values) {
this.codes = values;
return this;
}
public LanguageQuery excludedIds(Collection<UUID> values) {
this.excludedIds = values;
return this;
}
public LanguageQuery excludedIds(UUID value) {
this.excludedIds = List.of(value);
return this;
}
public LanguageQuery excludedIds(UUID... value) {
this.excludedIds = Arrays.asList(value);
return this;
}
public LanguageQuery authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
public LanguageQuery(
) {
}
@Override
protected Class<LanguageEntity> entityClass() {
return LanguageEntity.class;
}
@Override
protected Boolean isFalseQuery() {
return this.isEmpty(this.ids) || this.isEmpty(this.isActives) || this.isEmpty(this.excludedIds) || this.isEmpty(this.codes);
}
@Override
protected <X, Y> Predicate applyFilters(QueryContext<X, Y> queryContext) {
List<Predicate> predicates = new ArrayList<>();
if (this.ids != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(LanguageEntity._id));
for (UUID item : this.ids)
inClause.value(item);
predicates.add(inClause);
}
if (this.like != null && !this.like.isEmpty()) {
predicates.add(queryContext.CriteriaBuilder.like(queryContext.Root.get(LanguageEntity._code), this.like));
}
if (this.isActives != null) {
CriteriaBuilder.In<IsActive> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(LanguageEntity._isActive));
for (IsActive item : this.isActives)
inClause.value(item);
predicates.add(inClause);
}
if (this.codes != null) {
CriteriaBuilder.In<String> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(LanguageEntity._code));
for (String item : this.codes)
inClause.value(item);
predicates.add(inClause);
}
if (this.excludedIds != null) {
CriteriaBuilder.In<UUID> notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(LanguageEntity._id));
for (UUID item : this.excludedIds)
notInClause.value(item);
predicates.add(notInClause.not());
}
if (!predicates.isEmpty()) {
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
return queryContext.CriteriaBuilder.and(predicatesArray);
} else {
return null;
}
}
@Override
protected LanguageEntity convert(Tuple tuple, Set<String> columns) {
LanguageEntity item = new LanguageEntity();
item.setId(QueryBase.convertSafe(tuple, columns, LanguageEntity._id, UUID.class));
item.setCode(QueryBase.convertSafe(tuple, columns, LanguageEntity._code, String.class));
item.setPayload(QueryBase.convertSafe(tuple, columns, LanguageEntity._payload, String.class));
item.setCreatedAt(QueryBase.convertSafe(tuple, columns, LanguageEntity._createdAt, Instant.class));
item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, LanguageEntity._updatedAt, Instant.class));
item.setIsActive(QueryBase.convertSafe(tuple, columns, LanguageEntity._isActive, IsActive.class));
return item;
}
@Override
protected String fieldNameOf(FieldResolver item) {
if (item.match(Language._id)) return LanguageEntity._id;
else if (item.match(Language._code)) return LanguageEntity._code;
else if (item.match(Language._payload)) return LanguageEntity._payload;
else if (item.match(Language._createdAt)) return LanguageEntity._createdAt;
else if (item.match(Language._updatedAt)) return LanguageEntity._updatedAt;
else if (item.match(Language._hash)) return LanguageEntity._updatedAt;
else if (item.match(Language._isActive)) return LanguageEntity._isActive;
else return null;
}
}

View File

@ -0,0 +1,76 @@
package eu.eudat.query.lookup;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.query.LanguageQuery;
import gr.cite.tools.data.query.Lookup;
import gr.cite.tools.data.query.QueryFactory;
import java.util.List;
import java.util.UUID;
public class LanguageLookup extends Lookup {
private String like;
private List<IsActive> isActive;
private List<String> codes;
private List<UUID> ids;
private List<UUID> excludedIds;
public String getLike() {
return like;
}
public void setLike(String like) {
this.like = like;
}
public List<IsActive> getIsActive() {
return isActive;
}
public void setIsActive(List<IsActive> isActive) {
this.isActive = isActive;
}
public List<UUID> getIds() {
return ids;
}
public void setIds(List<UUID> ids) {
this.ids = ids;
}
public List<UUID> getExcludedIds() {
return excludedIds;
}
public void setExcludedIds(List<UUID> excludeIds) {
this.excludedIds = excludeIds;
}
public List<String> getCodes() {
return codes;
}
public void setCodes(List<String> codes) {
this.codes = codes;
}
public LanguageQuery enrich(QueryFactory queryFactory) {
LanguageQuery query = queryFactory.query(LanguageQuery.class);
if (this.like != null) query.like(this.like);
if (this.isActive != null) query.isActive(this.isActive);
if (this.codes != null) query.codes(this.codes);
if (this.ids != null) query.ids(this.ids);
if (this.excludedIds != null) query.excludedIds(this.excludedIds);
this.enrichCommon(query);
return query;
}
}

View File

@ -0,0 +1,19 @@
package eu.eudat.service.language;
import eu.eudat.model.Language;
import eu.eudat.model.persist.LanguagePersist;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.exception.MyForbiddenException;
import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.exception.MyValidationException;
import gr.cite.tools.fieldset.FieldSet;
import javax.management.InvalidApplicationException;
import java.util.UUID;
public interface LanguageService {
Language persist(LanguagePersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException;
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
}

View File

@ -0,0 +1,102 @@
package eu.eudat.service.language;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.Permission;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.LanguageEntity;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import eu.eudat.model.Language;
import eu.eudat.model.builder.LanguageBuilder;
import eu.eudat.model.deleter.LanguageDeleter;
import eu.eudat.model.persist.LanguagePersist;
import eu.eudat.service.dmpblueprint.DmpBlueprintServiceImpl;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.deleter.DeleterFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.exception.MyForbiddenException;
import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.exception.MyValidationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import jakarta.persistence.EntityManager;
import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import javax.management.InvalidApplicationException;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
@Service
public class LanguageServiceImpl implements LanguageService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpBlueprintServiceImpl.class));
private final EntityManager entityManager;
private final AuthorizationService authorizationService;
private final DeleterFactory deleterFactory;
private final BuilderFactory builderFactory;
private final ConventionService conventionService;
private final MessageSource messageSource;
private final ErrorThesaurusProperties errors;
public LanguageServiceImpl(
EntityManager entityManager, AuthorizationService authorizationService, DeleterFactory deleterFactory, BuilderFactory builderFactory,
ConventionService conventionService, MessageSource messageSource, ErrorThesaurusProperties errors){
this.entityManager = entityManager;
this.authorizationService = authorizationService;
this.deleterFactory = deleterFactory;
this.builderFactory = builderFactory;
this.conventionService = conventionService;
this.messageSource = messageSource;
this.errors = errors;
}
public Language persist(LanguagePersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException{
logger.debug(new MapLogEntry("persisting data").And("model", model).And("fields", fields));
this.authorizationService.authorizeForce(Permission.EditLanguage);
Boolean isUpdate = this.conventionService.isValidGuid(model.getId());
LanguageEntity data;
if (isUpdate) {
data = this.entityManager.find(LanguageEntity.class, model.getId());
if (data == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Language.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
} else {
data = new LanguageEntity();
data.setId(UUID.randomUUID());
data.setIsActive(IsActive.Active);
data.setCreatedAt(Instant.now());
}
data.setCode(model.getCode());
data.setPayload(model.getPayload());
data.setUpdatedAt(Instant.now());
if (isUpdate) this.entityManager.merge(data);
else this.entityManager.persist(data);
this.entityManager.flush();
return this.builderFactory.builder(LanguageBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, Language._id), data);
}
public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException {
logger.debug("deleting : {}", id);
this.authorizationService.authorizeForce(Permission.DeleteLanguage);
this.deleterFactory.deleter(LanguageDeleter.class).deleteAndSaveByIds(List.of(id));
}
}

View File

@ -0,0 +1,151 @@
package eu.eudat.controllers.v2;
import com.fasterxml.jackson.core.JsonProcessingException;
import eu.eudat.audit.AuditableAction;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.data.LanguageEntity;
import eu.eudat.model.Language;
import eu.eudat.model.builder.LanguageBuilder;
import eu.eudat.model.censorship.LanguageCensor;
import eu.eudat.model.persist.LanguagePersist;
import eu.eudat.model.result.QueryResult;
import eu.eudat.query.LanguageQuery;
import eu.eudat.query.lookup.LanguageLookup;
import eu.eudat.service.language.LanguageService;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.auditing.AuditService;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.exception.MyForbiddenException;
import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.MyValidate;
import jakarta.transaction.Transactional;
import jakarta.xml.bind.JAXBException;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.*;
import javax.management.InvalidApplicationException;
import java.util.AbstractMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@RestController
@RequestMapping(path = {"api/v2/language"})
public class LanguageV2Controller {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(LanguageV2Controller.class));
private final BuilderFactory builderFactory;
private final AuditService auditService;
private final CensorFactory censorFactory;
private final QueryFactory queryFactory;
private final MessageSource messageSource;
private final AuthorizationService authorizationService;
private final LanguageService languageService;
@Autowired
public LanguageV2Controller(
BuilderFactory builderFactory,
AuditService auditService,
CensorFactory censorFactory,
QueryFactory queryFactory,
MessageSource messageSource, AuthorizationService authorizationService,
LanguageService languageService) {
this.builderFactory = builderFactory;
this.auditService = auditService;
this.censorFactory = censorFactory;
this.queryFactory = queryFactory;
this.messageSource = messageSource;
this.authorizationService = authorizationService;
this.languageService = languageService;
}
@PostMapping("query")
public QueryResult<Language> query(@RequestBody LanguageLookup lookup) throws MyApplicationException, MyForbiddenException {
logger.debug("querying {}", Language.class.getSimpleName());
this.censorFactory.censor(LanguageCensor.class).censor(lookup.getProject(), null);
LanguageQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic);
List<LanguageEntity> data = query.collectAs(lookup.getProject());
List<Language> models = this.builderFactory.builder(LanguageBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data);
long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();
this.auditService.track(AuditableAction.Language_Query, "lookup", lookup);
return new QueryResult(models, count);
}
@GetMapping("{id}")
public Language get(@PathVariable("id") UUID id, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
logger.debug(new MapLogEntry("retrieving" + Language.class.getSimpleName()).And("id", id).And("fields", fieldSet));
this.censorFactory.censor(LanguageCensor.class).censor(fieldSet, null);
LanguageQuery query = this.queryFactory.query(LanguageQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(id);
Language model = this.builderFactory.builder(LanguageBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet));
if (model == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Language.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.auditService.track(AuditableAction.Language_Lookup, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("id", id),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
));
return model;
}
@GetMapping("code/{code}")
public Language get(@PathVariable("code") String code, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
logger.debug(new MapLogEntry("retrieving" + Language.class.getSimpleName()).And("code", code).And("fields", fieldSet));
this.censorFactory.censor(LanguageCensor.class).censor(fieldSet, null);
LanguageQuery query = this.queryFactory.query(LanguageQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).codes(code);
Language model = this.builderFactory.builder(LanguageBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet));
if (model == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{code, Language.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.auditService.track(AuditableAction.Language_Lookup, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("code", code),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
));
return model;
}
@PostMapping("persist")
@Transactional
public Language persist(@MyValidate @RequestBody LanguagePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, JsonProcessingException, InvalidApplicationException {
logger.debug(new MapLogEntry("persisting" + Language.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
this.censorFactory.censor(LanguageCensor.class).censor(fieldSet, null);
Language persisted = this.languageService.persist(model, fieldSet);
this.auditService.track(AuditableAction.Language_Persist, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("model", model),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
));
return persisted;
}
@DeleteMapping("{id}")
@Transactional
public void delete(@PathVariable("id") UUID id) throws MyForbiddenException, InvalidApplicationException {
logger.debug(new MapLogEntry("retrieving" + Language.class.getSimpleName()).And("id", id));
this.languageService.deleteAndSave(id);
this.auditService.track(AuditableAction.Language_Delete, "id", id);
}
}

View File

@ -407,10 +407,8 @@ public class ReferenceService {
if (urlPath.contains("openaire") || urlPath.contains("orcid") ){ if (urlPath.contains("openaire") || urlPath.contains("orcid") ){
if (lookup.getLike() != null) { if (lookup.getLike() != null) {
completedPath = completedPath.replace("{query}", lookup.getLike());
completedPath = completedPath.replace("{like}", lookup.getLike()); completedPath = completedPath.replace("{like}", lookup.getLike());
} else { } else {
completedPath = completedPath.replace("{query}", "*");
completedPath = completedPath.replace("{like}", "*"); completedPath = completedPath.replace("{like}", "*");
} }
} }

View File

@ -101,6 +101,13 @@ permissions:
clients: [ ] clients: [ ]
allowAnonymous: false allowAnonymous: false
allowAuthenticated: false allowAuthenticated: false
DeleteLanguage:
roles:
- Admin
claims: [ ]
clients: [ ]
allowAnonymous: false
allowAuthenticated: false
# Statistics # Statistics
BrowseStatistics: BrowseStatistics:
roles: [ ] roles: [ ]

View File

@ -1,3 +1,3 @@
tenant: tenant:
configEncryptionAesKey: 42J7rLaej8X+kUGR configEncryptionAesKey: rmpTvZnRWzyisUtFADBcZCn0q7Z75Xdz
configEncryptionAesIv: oL859DQRZP+AhfQ+ configEncryptionAesIv: ec05d521a23f80ad

View File

@ -232,43 +232,63 @@ const appRoutes: Routes = [
}, },
}, },
{ {
path: 'language-editor', path: 'languages',
loadChildren: () => import('./ui/language-editor/language-editor.module').then(m => m.LanguageEditorModule), loadChildren: () => import('./ui/admin/language/language.module').then(m => m.LanguageModule),
data: { data: {
breadcrumb: true, authContext: {
title: 'GENERAL.TITLES.LANGUAGE-EDITOR' permissions: [AppPermission.ViewLanguagePage]
},
...BreadcrumbService.generateRouteDataConfiguration({
title: 'BREADCRUMBS.LANGUAGES'
})
}, },
}, },
{ {
path: 'supportive-material', path: 'supportive-material',
loadChildren: () => import('./ui/supportive-material-editor/supportive-material-editor.module').then(m => m.SupportiveMaterialEditorModule), loadChildren: () => import('./ui/supportive-material-editor/supportive-material-editor.module').then(m => m.SupportiveMaterialEditorModule),
data: { data: {
breadcrumb: true, authContext: {
title: 'GENERAL.TITLES.SUPPORTIVE-MATERIAL' permissions: [AppPermission.ViewLanguagePage]
},
...BreadcrumbService.generateRouteDataConfiguration({
title: 'GENERAL.TITLES.SUPPORTIVE-MATERIAL'
})
}, },
}, },
{ {
path: 'references', path: 'references',
loadChildren: () => import('./ui/admin/reference/reference.module').then(m => m.ReferenceModule), loadChildren: () => import('./ui/admin/reference/reference.module').then(m => m.ReferenceModule),
data: { data: {
breadcrumb: true, authContext: {
title: 'GENERAL.TITLES.REFERENCES' permissions: [AppPermission.ViewReferencePage]
},
...BreadcrumbService.generateRouteDataConfiguration({
title: 'BREADCRUMBS.REFERENCES'
})
}, },
}, },
{ {
path: 'reference-type', path: 'reference-type',
loadChildren: () => import('./ui/admin/reference-type/reference-type.module').then(m => m.ReferenceTypeModule), loadChildren: () => import('./ui/admin/reference-type/reference-type.module').then(m => m.ReferenceTypeModule),
data: { data: {
breadcrumb: true, authContext: {
title: 'GENERAL.TITLES.REFERENCE-TYPES' permissions: [AppPermission.ViewReferenceTypePage]
},
...BreadcrumbService.generateRouteDataConfiguration({
title: 'BREADCRUMBS.REFERENCE-TYPES'
})
}, },
}, },
{ {
path: 'tenants', path: 'tenants',
loadChildren: () => import('./ui/admin/tenant/tenant.module').then(m => m.TenantModule), loadChildren: () => import('./ui/admin/tenant/tenant.module').then(m => m.TenantModule),
data: { data: {
breadcrumb: true, authContext: {
title: 'GENERAL.TITLES.TENANTS' permissions: [AppPermission.ViewTenantPage]
},
...BreadcrumbService.generateRouteDataConfiguration({
title: 'BREADCRUMBS.TENANTS'
})
}, },
}, },
{ {

View File

@ -18,6 +18,11 @@ export enum AppPermission {
ViewDescriptionTemplateTypePage = "ViewDescriptionTemplateTypePage", ViewDescriptionTemplateTypePage = "ViewDescriptionTemplateTypePage",
ViewDmpBlueprintPage = "ViewDmpBlueprintPage", ViewDmpBlueprintPage = "ViewDmpBlueprintPage",
ViewDescriptionTemplatePage = "ViewDescriptionTemplatePage", ViewDescriptionTemplatePage = "ViewDescriptionTemplatePage",
ViewSupportiveMaterialPage = 'ViewSupportiveMaterialPage',
ViewReferenceTypePage = 'ViewReferenceTypePage',
ViewReferencePage = 'ViewReferencePage',
ViewTenantPage = 'ViewTenantPage',
ViewLanguagePage = "ViewLanguagePage",
//ReferenceType //ReferenceType
BrowseReferenceType = "BrowseReferenceType", BrowseReferenceType = "BrowseReferenceType",
@ -33,5 +38,10 @@ export enum AppPermission {
BrowseReference = "BrowseReference", BrowseReference = "BrowseReference",
EditReference = "EditReference", EditReference = "EditReference",
DeleteReference = "DeleteReference", DeleteReference = "DeleteReference",
//Language
BrowseLanguage = "BrowseLanguage",
EditLanguage = "EditLanguage",
DeleteLanguage = "DeleteLanguage",
} }

View File

@ -61,6 +61,7 @@ import { UserSettingsService } from './services/user-settings/user-settings.serv
import { UserService } from './services/user/user.service'; import { UserService } from './services/user/user.service';
import { FileUtils } from './services/utilities/file-utils.service'; import { FileUtils } from './services/utilities/file-utils.service';
import { QueryParamsService } from './services/utilities/query-params.service'; import { QueryParamsService } from './services/utilities/query-params.service';
import { LanguageV2Service } from './services/language/language-v2.service';
// //
// //
// This is shared module that provides all the services. Its imported only once on the AppModule. // This is shared module that provides all the services. Its imported only once on the AppModule.
@ -140,7 +141,8 @@ export class CoreServiceModule {
DescriptionTemplateService, DescriptionTemplateService,
ReferenceTypeService, ReferenceTypeService,
TenantService, TenantService,
UserService UserService,
LanguageV2Service
], ],
}; };
} }

View File

@ -0,0 +1,13 @@
import { BaseEntity, BaseEntityPersist } from "@common/base/base-entity.model";
export interface Language extends BaseEntity{
code: string;
payload: string;
}
// Persist
export interface LanguagePersist extends BaseEntityPersist{
code: string;
payload: string;
}

View File

@ -0,0 +1,23 @@
import { Lookup } from "@common/model/lookup";
import { Guid } from "@common/types/guid";
import { IsActive } from "../common/enum/is-active.enum";
export class LanguageLookup extends Lookup implements LanguageFilter {
ids: Guid[];
excludedIds: Guid[];
like: string;
isActive: IsActive[];
codes: string[];
constructor() {
super();
}
}
export interface LanguageFilter {
ids: Guid[];
excludedIds: Guid[];
like: string;
isActive: IsActive[];
codes: string[];
}

View File

@ -0,0 +1,93 @@
import { Injectable } from '@angular/core';
import { IsActive } from '@app/core/common/enum/is-active.enum';
import { Language, LanguagePersist } from '@app/core/model/language/language';
import { LanguageLookup } from '@app/core/query/language.lookup';
import { MultipleAutoCompleteConfiguration } from '@app/library/auto-complete/multiple/multiple-auto-complete-configuration';
import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/single/single-auto-complete-configuration';
import { QueryResult } from '@common/model/query-result';
import { FilterService } from '@common/modules/text-filter/filter-service';
import { Guid } from '@common/types/guid';
import { Observable, throwError } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { nameof } from 'ts-simple-nameof';
import { ConfigurationService } from '../configuration/configuration.service';
import { BaseHttpV2Service } from '../http/base-http-v2.service';
@Injectable()
export class LanguageV2Service {
constructor(private http: BaseHttpV2Service, private configurationService: ConfigurationService, private filterService: FilterService) {
}
private get apiBase(): string { return `${this.configurationService.server}v2/language`; }
query(q: LanguageLookup): Observable<QueryResult<Language>> {
const url = `${this.apiBase}/query`;
return this.http.post<QueryResult<Language>>(url, q).pipe(catchError((error: any) => throwError(error)));
}
getSingle(id: Guid, reqFields: string[] = []): Observable<Language> {
const url = `${this.apiBase}/${id}`;
const options = { params: { f: reqFields } };
return this.http
.get<Language>(url, options).pipe(
catchError((error: any) => throwError(error)));
}
persist(item: LanguagePersist): Observable<Language> {
const url = `${this.apiBase}/persist`;
return this.http
.post<Language>(url, item).pipe(
catchError((error: any) => throwError(error)));
}
delete(id: Guid): Observable<Language> {
const url = `${this.apiBase}/${id}`;
return this.http
.delete<Language>(url).pipe(
catchError((error: any) => throwError(error)));
}
//
// Autocomplete Commons
//
// tslint:disable-next-line: member-ordering
singleAutocompleteConfiguration: SingleAutoCompleteConfiguration = {
initialItems: (data?: any) => this.query(this.buildAutocompleteLookup()).pipe(map(x => x.items)),
filterFn: (searchQuery: string, data?: any) => this.query(this.buildAutocompleteLookup(searchQuery)).pipe(map(x => x.items)),
getSelectedItem: (selectedItem: any) => this.query(this.buildAutocompleteLookup(null, null, [selectedItem])).pipe(map(x => x.items[0])),
displayFn: (item: Language) => item.code,
titleFn: (item: Language) => item.code,
valueAssign: (item: Language) => item.id,
};
// tslint:disable-next-line: member-ordering
multipleAutocompleteConfiguration: MultipleAutoCompleteConfiguration = {
initialItems: (excludedItems: any[], data?: any) => this.query(this.buildAutocompleteLookup(null, excludedItems ? excludedItems : null)).pipe(map(x => x.items)),
filterFn: (searchQuery: string, excludedItems: any[]) => this.query(this.buildAutocompleteLookup(searchQuery, excludedItems)).pipe(map(x => x.items)),
getSelectedItems: (selectedItems: any[]) => this.query(this.buildAutocompleteLookup(null, null, selectedItems)).pipe(map(x => x.items)),
displayFn: (item: Language) => item.code,
titleFn: (item: Language) => item.code,
valueAssign: (item: Language) => item.id,
};
private buildAutocompleteLookup(like?: string, excludedIds?: Guid[], ids?: Guid[]): LanguageLookup {
const lookup: LanguageLookup = new LanguageLookup();
lookup.page = { size: 100, offset: 0 };
if (excludedIds && excludedIds.length > 0) { lookup.excludedIds = excludedIds; }
if (ids && ids.length > 0) { lookup.ids = ids; }
lookup.isActive = [IsActive.Active];
lookup.project = {
fields: [
nameof<Language>(x => x.id),
nameof<Language>(x => x.code)
]
};
lookup.order = { items: [nameof<Language>(x => x.code)] };
if (like) { lookup.like = this.filterService.transformLike(like); }
return lookup;
}
}

View File

@ -311,18 +311,18 @@ export class EnumUtils {
switch (status) { switch (status) {
case ReferenceType.Taxonomies: return this.language.instant('TYPES.REFERENCE-TYPE.TAXONOMY'); case ReferenceType.Taxonomies: return this.language.instant('TYPES.REFERENCE-TYPE.TAXONOMY');
case ReferenceType.Licenses: return this.language.instant('TYPES.REFERENCE-TYPE.LICENCE'); case ReferenceType.Licenses: return this.language.instant('TYPES.REFERENCE-TYPE.LICENCE');
case ReferenceType.Publications: return this.language.instant('TYPES.REFERENCE-TYPE.GET'); case ReferenceType.Publications: return this.language.instant('TYPES.REFERENCE-TYPE.PUBLICATION');
case ReferenceType.Journals: return this.language.instant('TYPES.REFERENCE-TYPE.GET'); case ReferenceType.Journals: return this.language.instant('TYPES.REFERENCE-TYPE.JOURNAL');
case ReferenceType.PubRepositories: return this.language.instant('TYPES.REFERENCE-TYPE.GET'); case ReferenceType.PubRepositories: return this.language.instant('TYPES.REFERENCE-TYPE.PUB-REPOSITORY');
case ReferenceType.DataRepositories: return this.language.instant('TYPES.REFERENCE-TYPE.GET'); case ReferenceType.DataRepositories: return this.language.instant('TYPES.REFERENCE-TYPE.DATA-REPOSITORY');
case ReferenceType.Registries: return this.language.instant('TYPES.REFERENCE-TYPE.GET'); case ReferenceType.Registries: return this.language.instant('TYPES.REFERENCE-TYPE.REGISTRY');
case ReferenceType.Services: return this.language.instant('TYPES.REFERENCE-TYPE.GET'); case ReferenceType.Services: return this.language.instant('TYPES.REFERENCE-TYPE.SERVICE');
case ReferenceType.Project: return this.language.instant('TYPES.REFERENCE-TYPE.GET'); case ReferenceType.Project: return this.language.instant('TYPES.REFERENCE-TYPE.PROJECT');
case ReferenceType.Funder: return this.language.instant('TYPES.REFERENCE-TYPE.GET'); case ReferenceType.Funder: return this.language.instant('TYPES.REFERENCE-TYPE.FUNDER');
case ReferenceType.Datasets: return this.language.instant('TYPES.REFERENCE-TYPE.GET'); case ReferenceType.Datasets: return this.language.instant('TYPES.REFERENCE-TYPE.DATASET');
case ReferenceType.Organizations: return this.language.instant('TYPES.REFERENCE-TYPE.ORGANISATION'); case ReferenceType.Organizations: return this.language.instant('TYPES.REFERENCE-TYPE.ORGANISATION');
case ReferenceType.Grants: return this.language.instant('TYPES.REFERENCE-TYPE.GET'); case ReferenceType.Grants: return this.language.instant('TYPES.REFERENCE-TYPE.GRANT');
case ReferenceType.Researcher: return this.language.instant('TYPES.REFERENCE-TYPE.GET'); case ReferenceType.Researcher: return this.language.instant('TYPES.REFERENCE-TYPE.RESEARCHER');
} }
} }

View File

@ -0,0 +1,53 @@
<div class="tenant-editor">
<div class="col-md-8 offset-md-2 colums-gapped">
<div class="row align-items-center mb-4" *ngIf="formGroup">
<div class="col-auto">
<h3 *ngIf="isNew && !isClone">{{'LANGUAGE-EDITOR.NEW' | translate}}</h3>
<app-navigation-breadcrumb />
</div>
<div class="col-auto">
<button mat-button class="action-btn" (click)="cancel()" type="button">{{'LANGUAGE-EDITOR.ACTIONS.CANCEL' | translate}}</button>
</div>
<div class="col-auto" *ngIf="!isNew">
<button mat-button class="action-btn" type="button" (click)="delete()">
<mat-icon>delete</mat-icon>
{{'LANGUAGE-EDITOR.ACTIONS.DELETE' | translate}}
</button>
</div>
<div class="col-auto" *ngIf="canSave">
<button mat-button class="action-btn" (click)="formSubmit()">
<mat-icon>save</mat-icon>
{{'LANGUAGE-EDITOR.ACTIONS.SAVE' | translate}}
</button>
</div>
</div>
<form *ngIf="formGroup" (ngSubmit)="formSubmit()">
<mat-card appearance="outlined">
<mat-card-header>
<mat-card-title *ngIf="isNew">{{'LANGUAGE-EDITOR.NEW' | translate}}</mat-card-title>
</mat-card-header>
<mat-card-content>
<div class="row">
<div class="col-4">
<mat-form-field class="w-100">
<mat-label>{{'LANGUAGE-EDITOR.FIELDS.CODE' | translate}}</mat-label>
<input matInput type="text" name="code" [formControl]="formGroup.get('code')" required>
<mat-error *ngIf="formGroup.get('code').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-4">
<mat-form-field class="w-100">
<mat-label>{{'LANGUAGE-EDITOR.FIELDS.PAYLOAD' | translate}}</mat-label>
<input matInput type="text" name="payload" [formControl]="formGroup.get('payload')" required>
<mat-error *ngIf="formGroup.get('payload').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
</div>
</mat-card-content>
</mat-card>
</form>
</div>
</div>

View File

@ -0,0 +1,43 @@
.tenant-editor {
margin-top: 1.3rem;
margin-left: 1em;
margin-right: 3em;
.remove {
background-color: white;
color: black;
}
.add {
background-color: white;
color: #009700;
}
}
::ng-deep .mat-checkbox-checked.mat-accent .mat-checkbox-background, .mat-checkbox-indeterminate.mat-accent .mat-checkbox-background {
background-color: var(--primary-color-3);
// background-color: #0070c0;
}
::ng-deep .mat-checkbox-disabled.mat-checkbox-checked .mat-checkbox-background, .mat-checkbox-disabled.mat-checkbox-indeterminate .mat-checkbox-background {
background-color: #b0b0b0;
}
.action-btn {
border-radius: 30px;
background-color: var(--secondary-color);
border: 1px solid transparent;
padding-left: 2em;
padding-right: 2em;
box-shadow: 0px 3px 6px #1E202029;
transition-property: background-color, color;
transition-duration: 200ms;
transition-delay: 50ms;
transition-timing-function: ease-in-out;
&:disabled{
background-color: #CBCBCB;
color: #FFF;
border: 0px;
}
}

View File

@ -0,0 +1,186 @@
import { Component, OnInit } from '@angular/core';
import { UntypedFormGroup } from '@angular/forms';
import { MatDialog } from '@angular/material/dialog';
import { ActivatedRoute, Router } from '@angular/router';
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
// import { BreadcrumbItem } from '@app/ui/misc/breadcrumb/definition/breadcrumb-item';
import { DatePipe } from '@angular/common';
import { IsActive } from '@app/core/common/enum/is-active.enum';
import { AppPermission } from '@app/core/common/enum/permission.enum';
import { Language, LanguagePersist } from '@app/core/model/language/language';
import { AuthService } from '@app/core/services/auth/auth.service';
import { LoggingService } from '@app/core/services/logging/logging-service';
import { MatomoService } from '@app/core/services/matomo/matomo-service';
import { FileUtils } from '@app/core/services/utilities/file-utils.service';
import { QueryParamsService } from '@app/core/services/utilities/query-params.service';
import { MultipleAutoCompleteConfiguration } from '@app/library/auto-complete/multiple/multiple-auto-complete-configuration';
import { BaseEditor } from '@common/base/base-editor';
import { FormService } from '@common/forms/form-service';
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service';
import { FilterService } from '@common/modules/text-filter/filter-service';
import { Guid } from '@common/types/guid';
import { TranslateService } from '@ngx-translate/core';
import { map, takeUntil } from 'rxjs/operators';
import { LanguageEditorResolver } from './language-editor.resolver';
import { LanguageEditorService } from './language-editor.service';
import { LanguageEditorModel } from './language-editor.model';
import { MatChipEditedEvent, MatChipInputEvent } from '@angular/material/chips';
import { LanguageV2Service } from '@app/core/services/language/language-v2.service';
@Component({
selector: 'app-language-editor-component',
templateUrl: 'language-editor.component.html',
styleUrls: ['./language-editor.component.scss'],
providers: [LanguageEditorService]
})
export class LanguageEditorComponent extends BaseEditor<LanguageEditorModel, Language> implements OnInit {
isNew = true;
isDeleted = false;
formGroup: UntypedFormGroup = null;
showInactiveDetails = false;
depositCodes: string[] = [];
fileTransformersCodes: string[] = [];
protected get canDelete(): boolean {
return !this.isDeleted && !this.isNew && this.hasPermission(this.authService.permissionEnum.DeleteLanguage);
}
protected get canSave(): boolean {
return !this.isDeleted && this.hasPermission(this.authService.permissionEnum.EditLanguage);
}
protected get canFinalize(): boolean {
return !this.isDeleted && this.hasPermission(this.authService.permissionEnum.EditLanguage);
}
private hasPermission(permission: AppPermission): boolean {
return this.authService.hasPermission(permission) || this.editorModel?.permissions?.includes(permission);
}
constructor(
// BaseFormEditor injected dependencies
protected dialog: MatDialog,
protected language: TranslateService,
protected formService: FormService,
protected router: Router,
protected uiNotificationService: UiNotificationService,
protected httpErrorHandlingService: HttpErrorHandlingService,
protected filterService: FilterService,
protected datePipe: DatePipe,
protected route: ActivatedRoute,
protected queryParamsService: QueryParamsService,
// Rest dependencies. Inject any other needed deps here:
public authService: AuthService,
public enumUtils: EnumUtils,
private languageV2Service: LanguageV2Service,
private logger: LoggingService,
private languageEditorService: LanguageEditorService,
private fileUtils: FileUtils,
private matomoService: MatomoService
) {
super(dialog, language, formService, router, uiNotificationService, httpErrorHandlingService, filterService, datePipe, route, queryParamsService);
}
ngOnInit(): void {
this.matomoService.trackPageView('Admin: Languages');
super.ngOnInit();
}
getItem(itemId: Guid, successFunction: (item: Language) => void) {
this.languageV2Service.getSingle(itemId, LanguageEditorResolver.lookupFields())
.pipe(map(data => data as Language), takeUntil(this._destroyed))
.subscribe(
data => successFunction(data),
error => this.onCallbackError(error)
);
}
prepareForm(data: Language) {
try {
this.editorModel = data ? new LanguageEditorModel().fromModel(data) : new LanguageEditorModel();
this.isDeleted = data ? data.isActive === IsActive.Inactive : false;
this.buildForm();
} catch (error) {
this.logger.error('Could not parse Language item: ' + data + error);
this.uiNotificationService.snackBarNotification(this.language.instant('COMMONS.ERRORS.DEFAULT'), SnackBarNotificationLevel.Error);
}
}
buildForm() {
this.formGroup = this.editorModel.buildForm(null, this.isDeleted || !this.authService.hasPermission(AppPermission.EditLanguage));
this.languageEditorService.setValidationErrorModel(this.editorModel.validationErrorModel);
}
refreshData(): void {
this.getItem(this.editorModel.id, (data: Language) => this.prepareForm(data));
}
refreshOnNavigateToData(id?: Guid): void {
this.formGroup.markAsPristine();
let route = [];
if (id === null) {
route.push('../..');
} else if (this.isNew) {
route.push('../' + id);
} else {
route.push('..');
}
this.router.navigate(route, { queryParams: { 'lookup': this.queryParamsService.serializeLookup(this.lookupParams), 'lv': ++this.lv }, replaceUrl: true, relativeTo: this.route });
}
persistEntity(onSuccess?: (response) => void): void {
const formData = this.formService.getValue(this.formGroup.value) as LanguagePersist;
this.languageV2Service.persist(formData)
.pipe(takeUntil(this._destroyed)).subscribe(
complete => onSuccess ? onSuccess(complete) : this.onCallbackSuccess(complete),
error => this.onCallbackError(error)
);
}
formSubmit(): void {
this.formService.touchAllFormFields(this.formGroup);
if (!this.isFormValid()) {
return;
}
this.persistEntity();
}
public delete() {
const value = this.formGroup.value;
if (value.id) {
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
maxWidth: '300px',
data: {
message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.DELETE-ITEM'),
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CONFIRM'),
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL')
}
});
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
if (result) {
this.languageV2Service.delete(value.id).pipe(takeUntil(this._destroyed))
.subscribe(
complete => this.onCallbackSuccess(),
error => this.onCallbackError(error)
);
}
});
}
}
clearErrorModel() {
this.editorModel.validationErrorModel.clear();
this.formService.validateAllFormFields(this.formGroup);
}
}

View File

@ -0,0 +1,50 @@
import { UntypedFormBuilder, UntypedFormGroup, Validators } from "@angular/forms";
import { Language, LanguagePersist } from "@app/core/model/language/language";
import { BaseEditorModel } from "@common/base/base-form-editor-model";
import { BackendErrorValidator } from "@common/forms/validation/custom-validator";
import { ValidationErrorModel } from "@common/forms/validation/error-model/validation-error-model";
import { Validation, ValidationContext } from "@common/forms/validation/validation-context";
export class LanguageEditorModel extends BaseEditorModel implements LanguagePersist {
code: string;
payload: string;
permissions: string[];
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel();
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
constructor() { super(); }
public fromModel(item: Language): LanguageEditorModel {
if (item) {
super.fromModel(item);
this.code = item.code;
this.payload = item.payload;
}
return this;
}
buildForm(context: ValidationContext = null, disabled: boolean = false): UntypedFormGroup {
if (context == null) { context = this.createValidationContext(); }
return this.formBuilder.group({
id: [{ value: this.id, disabled: disabled }, context.getValidation('id').validators],
code: [{ value: this.code, disabled: disabled }, context.getValidation('code').validators],
payload: [{ value: this.payload, disabled: disabled }, context.getValidation('payload').validators],
hash: [{ value: this.hash, disabled: disabled }, context.getValidation('hash').validators]
});
}
createValidationContext(): ValidationContext {
const baseContext: ValidationContext = new ValidationContext();
const baseValidationArray: Validation[] = new Array<Validation>();
baseValidationArray.push({ key: 'id', validators: [BackendErrorValidator(this.validationErrorModel, 'id')] });
baseValidationArray.push({ key: 'code', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'code')] });
baseValidationArray.push({ key: 'payload', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'payload')] });
baseValidationArray.push({ key: 'hash', validators: [] });
baseContext.validation = baseValidationArray;
return baseContext;
}
}

View File

@ -0,0 +1,42 @@
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Language } from '@app/core/model/language/language';
import { LanguageV2Service } from '@app/core/services/language/language-v2.service';
import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service';
import { BaseEditorResolver } from '@common/base/base-editor.resolver';
import { Guid } from '@common/types/guid';
import { takeUntil, tap } from 'rxjs/operators';
import { nameof } from 'ts-simple-nameof';
@Injectable()
export class LanguageEditorResolver extends BaseEditorResolver {
constructor(private languageV2Service: LanguageV2Service, private breadcrumbService: BreadcrumbService) {
super();
}
public static lookupFields(): string[] {
return [
...BaseEditorResolver.lookupFields(),
nameof<Language>(x => x.id),
nameof<Language>(x => x.code),
nameof<Language>(x => x.payload),
nameof<Language>(x => x.createdAt),
nameof<Language>(x => x.updatedAt),
nameof<Language>(x => x.hash),
nameof<Language>(x => x.isActive)
]
}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
const fields = [
...LanguageEditorResolver.lookupFields()
];
const id = route.paramMap.get('id');
if (id != null) {
return this.languageV2Service.getSingle(Guid.parse(id), fields).pipe(tap(x => this.breadcrumbService.addIdResolvedValue(x.id?.toString(), x.code)), takeUntil(this._destroyed));
}
}
}

View File

@ -0,0 +1,15 @@
import { Injectable } from "@angular/core";
import { ValidationErrorModel } from "@common/forms/validation/error-model/validation-error-model";
@Injectable()
export class LanguageEditorService {
private validationErrorModel: ValidationErrorModel;
public setValidationErrorModel(validationErrorModel: ValidationErrorModel): void {
this.validationErrorModel = validationErrorModel;
}
public getValidationErrorModel(): ValidationErrorModel {
return this.validationErrorModel;
}
}

View File

@ -0,0 +1,41 @@
import { DragDropModule } from '@angular/cdk/drag-drop';
import { NgModule } from "@angular/core";
import { AutoCompleteModule } from "@app/library/auto-complete/auto-complete.module";
import { UrlListingModule } from '@app/library/url-listing/url-listing.module';
import { CommonFormattingModule } from '@common/formatting/common-formatting.module';
import { CommonFormsModule } from '@common/forms/common-forms.module';
import { ConfirmationDialogModule } from '@common/modules/confirmation-dialog/confirmation-dialog.module';
import { HybridListingModule } from "@common/modules/hybrid-listing/hybrid-listing.module";
import { TextFilterModule } from "@common/modules/text-filter/text-filter.module";
import { UserSettingsModule } from "@common/modules/user-settings/user-settings.module";
import { CommonUiModule } from '@common/ui/common-ui.module';
import { NgxDropzoneModule } from "ngx-dropzone";
import { LanguageRoutingModule } from './language.routing';
import { LanguageEditorComponent } from './editor/language-editor.component';
import { LanguageListingComponent } from './listing/language-listing.component';
import { LanguageListingFiltersComponent } from "./listing/filters/language-listing-filters.component";
import { RichTextEditorModule } from '@app/library/rich-text-editor/rich-text-editor.module';
@NgModule({
imports: [
CommonUiModule,
CommonFormsModule,
UrlListingModule,
ConfirmationDialogModule,
LanguageRoutingModule,
NgxDropzoneModule,
DragDropModule,
AutoCompleteModule,
HybridListingModule,
TextFilterModule,
UserSettingsModule,
CommonFormattingModule,
RichTextEditorModule
],
declarations: [
LanguageEditorComponent,
LanguageListingComponent,
LanguageListingFiltersComponent
]
})
export class LanguageModule { }

View File

@ -0,0 +1,57 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { LanguageEditorComponent } from './editor/language-editor.component';
import { LanguageListingComponent } from './listing/language-listing.component';
import { AppPermission } from '@app/core/common/enum/permission.enum';
import { AuthGuard } from '@app/core/auth-guard.service';
import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service';
import { PendingChangesGuard } from '@common/forms/pending-form-changes/pending-form-changes-guard.service';
import { LanguageEditorResolver } from './editor/language-editor.resolver';
const routes: Routes = [
{
path: '',
component: LanguageListingComponent,
canActivate: [AuthGuard]
},
{
path: 'new',
canActivate: [AuthGuard],
component: LanguageEditorComponent,
canDeactivate: [PendingChangesGuard],
data: {
authContext: {
permissions: [AppPermission.EditLanguage]
},
...BreadcrumbService.generateRouteDataConfiguration({
title: 'BREADCRUMBS.NEW-LANGUAGE'
})
}
},
{
path: ':id',
canActivate: [AuthGuard],
component: LanguageEditorComponent,
canDeactivate: [PendingChangesGuard],
resolve: {
'entity': LanguageEditorResolver
},
data: {
...BreadcrumbService.generateRouteDataConfiguration({
title: 'BREADCRUMBS.EDIT-LANGUAGE'
}),
authContext: {
permissions: [AppPermission.EditLanguage]
}
}
},
{ path: '**', loadChildren: () => import('@common/modules/page-not-found/page-not-found.module').then(m => m.PageNotFoundModule) },
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
providers: [LanguageEditorResolver]
})
export class LanguageRoutingModule { }

View File

@ -0,0 +1,36 @@
<div class="d-flex align-items-center gap-1-rem">
<button mat-flat-button [matMenuTriggerFor]="filterMenu" #filterMenuTrigger="matMenuTrigger" (click)="updateFilters()" class="filter-button">
<mat-icon aria-hidden="false" [matBadgeHidden]="!appliedFilterCount" [matBadge]="appliedFilterCount" matBadgeColor="warn" matBadgeSize="small">filter_alt</mat-icon>
{{'COMMONS.LISTING-COMPONENT.SEARCH-FILTER-BTN' | translate}}
</button>
<mat-menu #filterMenu>
<div class="p-3" (click)="$event?.stopPropagation?.()">
<div class="search-listing-filters-container">
<div class="d-flex align-items-center justify-content-between">
<h4>{{'TENANT-LISTING.FILTER.TITLE' | translate}}</h4>
<button color="accent" mat-button (click)="clearFilters()">
{{'COMMONS.LISTING-COMPONENT.CLEAR-ALL-FILTERS' | translate}}
</button>
</div>
<mat-slide-toggle labelPosition="before" [(ngModel)]="internalFilters.isActive">
{{'TENANT-LISTING.FILTER.IS-ACTIVE' | translate}}
</mat-slide-toggle>
<div class="d-flex justify-content-end align-items-center mt-4 gap-1-rem">
<button mat-stroked-button color="primary" (click)="filterMenuTrigger?.closeMenu()">
{{'TENANT-LISTING.FILTER.CANCEL' | translate}}
</button>
<button mat-raised-button color="primary" (click)="filterMenuTrigger.closeMenu(); applyFilters();">
{{'TENANT-LISTING.FILTER.APPLY-FILTERS' | translate}}
</button>
</div>
</div>
</div>
</mat-menu>
<app-expandable-search-field [(value)]=internalFilters.like (valueChange)="onSearchTermChange($event)" />
</div>

View File

@ -0,0 +1,21 @@
::ng-deep.mat-mdc-menu-panel {
max-width: 100% !important;
height: 100% !important;
}
:host::ng-deep.mat-mdc-menu-content:not(:empty) {
padding-top: 0 !important;
}
.filter-button{
padding-top: .6rem;
padding-bottom: .6rem;
// .mat-icon{
// font-size: 1.5em;
// width: 1.2em;
// height: 1.2em;
// }
}

View File

@ -0,0 +1,94 @@
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
import { IsActive } from '@app/core/common/enum/is-active.enum';
import { TenantFilter } from '@app/core/query/tenant.lookup';
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
import { BaseComponent } from '@common/base/base.component';
import { nameof } from 'ts-simple-nameof';
@Component({
selector: 'app-language-listing-filters',
templateUrl: './language-listing-filters.component.html',
styleUrls: ['./language-listing-filters.component.scss']
})
export class LanguageListingFiltersComponent extends BaseComponent implements OnInit, OnChanges {
@Input() readonly filter: TenantFilter;
@Output() filterChange = new EventEmitter<TenantFilter>();
// * State
internalFilters: LanguageListingFilters = this._getEmptyFilters();
protected appliedFilterCount: number = 0;
constructor(
public enumUtils: EnumUtils,
) { super(); }
ngOnInit() {
}
ngOnChanges(changes: SimpleChanges): void {
const filterChange = changes[nameof<LanguageListingFiltersComponent>(x => x.filter)]?.currentValue as TenantFilter;
if (filterChange) {
this.updateFilters()
}
}
onSearchTermChange(searchTerm: string): void {
this.applyFilters()
}
protected updateFilters(): void {
this.internalFilters = this._parseToInternalFilters(this.filter);
this.appliedFilterCount = this._computeAppliedFilters(this.internalFilters);
}
protected applyFilters(): void {
const { isActive, like } = this.internalFilters ?? {}
this.filterChange.emit({
...this.filter,
like,
isActive: isActive ? [IsActive.Active] : [IsActive.Inactive]
})
}
private _parseToInternalFilters(inputFilter: TenantFilter): LanguageListingFilters {
if (!inputFilter) {
return this._getEmptyFilters();
}
let { excludedIds, ids, isActive, like } = inputFilter;
return {
isActive: (isActive ?? [])?.includes(IsActive.Active) || !isActive?.length,
like: like
}
}
private _getEmptyFilters(): LanguageListingFilters {
return {
isActive: true,
like: null,
}
}
private _computeAppliedFilters(filters: LanguageListingFilters): number {
let count = 0;
if (filters?.isActive) {
count++
}
return count;
}
clearFilters() {
this.internalFilters = this._getEmptyFilters();
}
}
interface LanguageListingFilters {
isActive: boolean;
like: string;
}

View File

@ -0,0 +1,95 @@
<div class="row language-listing">
<div class="col-md-8 offset-md-2">
<div class="row mb-4 mt-3">
<div class="col">
<h4>{{'LANGUAGE-LISTING.TITLE' | translate}}</h4>
<app-navigation-breadcrumb />
</div>
<div class="col-auto">
<button mat-raised-button class="create-btn"
*ngIf="authService.hasPermission(authService.permissionEnum.EditLanguage)"
[routerLink]="['/languages/new']">
<mat-icon>add</mat-icon>
{{'LANGUAGE-LISTING.CREATE' | translate}}
</button>
</div>
</div>
<app-hybrid-listing [rows]="gridRows" [columns]="gridColumns" [visibleColumns]="visibleColumns"
[count]="totalElements" [offset]="currentPageNumber" [limit]="lookup.page.size"
[defaultSort]="lookup.order?.items" [externalSorting]="true" (rowActivated)="onRowActivated($event)"
(pageLoad)="alterPage($event)" (columnSort)="onColumnSort($event)"
(columnsChanged)="onColumnsChanged($event)" [listItemTemplate]="listItemTemplate">
<app-language-listing-filters hybrid-listing-filters [(filter)]="lookup"
(filterChange)="filterChanged($event)" />
<app-user-settings-picker [key]="userSettingsKey" [userPreference]="lookup"
(onSettingSelected)="changeSetting($event)" [autoSelectUserSettings]="autoSelectUserSettings"
user-preference-settings />
</app-hybrid-listing>
</div>
</div>
<ng-template #listItemTemplate let-item="item" let-isColumnSelected="isColumnSelected">
<div class="d-flex align-items-center p-3 gap-1-rem">
<div class="row">
<ng-container *ngIf="isColumnSelected('name')">
<a class="buttonLinkClass" [routerLink]="'./' + item?.id" class="col-12"
(click)="$event.stopPropagation()">{{item?.name | nullifyValue}}</a>
<br />
</ng-container>
<ng-container *ngIf="isColumnSelected('status')">
<div class="col-auto">
<div class="status-chip"
[ngClass]="{'status-chip-finalized': item.status === descriptionTemplateTypeStatuses.Finalized, 'status-chip-draft' : item.status === descriptionTemplateTypeStatuses.Draft}">
{{enumUtils.toDescriptionTemplateTypeStatusString(item.status) | nullifyValue}}
</div>
</div>
</ng-container>
<ng-container *ngIf="isColumnSelected('createdAt')">
<span class="col-12">
{{'LANGUAGE-LISTING.FIELDS.CREATED-AT' | translate}}:
<small>
{{item?.createdAt | dateTimeFormatter : 'short' | nullifyValue}}
</small>
</span>
<br>
</ng-container>
<ng-container *ngIf="isColumnSelected('updatedAt')">
<span class="col-12">
{{'LANGUAGE-LISTING.FIELDS.UPDATED-AT' | translate}}:
<small>
{{item?.updatedAt | dateTimeFormatter : 'short' | nullifyValue}}
</small>
</span>
</ng-container>
</div>
</div>
</ng-template>
<ng-template #actions let-row="row" let-item>
<div class="row" (click)="$event.stopPropagation()">
<div class="col-auto">
<button mat-icon-button [matMenuTriggerFor]="actionsMenu">
<mat-icon>more_horiz</mat-icon>
</button>
<mat-menu #actionsMenu="matMenu">
<button mat-menu-item [routerLink]="['/language/' + row.id]">
<mat-icon>edit</mat-icon>{{'LANGUAGE-LISTING.ACTIONS.EDIT' | translate}}
</button>
<button mat-menu-item (click)="deleteType(row.id)">
<mat-icon>delete</mat-icon>
{{'LANGUAGE-LISTING.ACTIONS.DELETE' | translate}}
</button>
</mat-menu>
</div>
</div>
</ng-template>

View File

@ -0,0 +1,60 @@
.language-listing {
margin-top: 1.3rem;
margin-left: 1rem;
margin-right: 2rem;
.mat-header-row{
background: #f3f5f8;
}
.mat-card {
margin: 16px 0;
padding: 0px;
}
.mat-row {
cursor: pointer;
min-height: 4.5em;
}
mat-row:hover {
background-color: #eef5f6;
}
.mat-fab-bottom-right {
float: right;
z-index: 5;
}
}
.create-btn {
border-radius: 30px;
background-color: var(--secondary-color);
padding-left: 2em;
padding-right: 2em;
// color: #000;
.button-text{
display: inline-block;
}
}
.dlt-btn {
color: rgba(0, 0, 0, 0.54);
}
.status-chip{
border-radius: 20px;
padding-left: 1em;
padding-right: 1em;
padding-top: 0.2em;
font-size: .8em;
}
.status-chip-finalized{
color: #568b5a;
background: #9dd1a1 0% 0% no-repeat padding-box;
}
.status-chip-draft{
color: #00c4ff;
background: #d3f5ff 0% 0% no-repeat padding-box;
}

View File

@ -0,0 +1,164 @@
import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ActivatedRoute, Router } from '@angular/router';
import { IsActive } from '@app/core/common/enum/is-active.enum';
import { Language } from '@app/core/model/language/language';
import { LanguageLookup } from '@app/core/query/language.lookup';
import { AuthService } from '@app/core/services/auth/auth.service';
import { LanguageV2Service } from '@app/core/services/language/language-v2.service';
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
import { QueryParamsService } from '@app/core/services/utilities/query-params.service';
import { BaseListingComponent } from '@common/base/base-listing-component';
import { PipeService } from '@common/formatting/pipe.service';
import { DataTableDateTimeFormatPipe } from '@common/formatting/pipes/date-time-format.pipe';
import { QueryResult } from '@common/model/query-result';
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service';
import { ColumnDefinition, ColumnsChangedEvent, HybridListingComponent, PageLoadEvent } from '@common/modules/hybrid-listing/hybrid-listing.component';
import { Guid } from '@common/types/guid';
import { TranslateService } from '@ngx-translate/core';
import { Observable } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { nameof } from 'ts-simple-nameof';
@Component({
templateUrl: './language-listing.component.html',
styleUrls: ['./language-listing.component.scss']
})
export class LanguageListingComponent extends BaseListingComponent<Language, LanguageLookup> implements OnInit {
publish = false;
userSettingsKey = { key: 'LanguageListingUserSettings' };
propertiesAvailableForOrder: ColumnDefinition[];
// @ViewChild('LanguageStatus', { static: true }) LanguageStatus?: TemplateRef<any>;
@ViewChild('actions', { static: true }) actions?: TemplateRef<any>;
@ViewChild(HybridListingComponent, { static: true }) hybridListingComponent: HybridListingComponent;
private readonly lookupFields: string[] = [
nameof<Language>(x => x.id),
nameof<Language>(x => x.code),
nameof<Language>(x => x.updatedAt),
nameof<Language>(x => x.createdAt),
nameof<Language>(x => x.hash),
nameof<Language>(x => x.isActive)
];
rowIdentity = x => x.id;
constructor(
protected router: Router,
protected route: ActivatedRoute,
protected uiNotificationService: UiNotificationService,
protected httpErrorHandlingService: HttpErrorHandlingService,
protected queryParamsService: QueryParamsService,
private languageV2Service: LanguageV2Service,
public authService: AuthService,
private pipeService: PipeService,
public enumUtils: EnumUtils,
private language: TranslateService,
private dialog: MatDialog
) {
super(router, route, uiNotificationService, httpErrorHandlingService, queryParamsService);
// Lookup setup
// Default lookup values are defined in the user settings class.
this.lookup = this.initializeLookup();
}
ngOnInit() {
super.ngOnInit();
}
protected initializeLookup(): LanguageLookup {
const lookup = new LanguageLookup();
lookup.metadata = { countAll: true };
lookup.page = { offset: 0, size: this.ITEMS_PER_PAGE };
lookup.isActive = [IsActive.Active];
lookup.order = { items: [this.toDescSortField(nameof<Language>(x => x.createdAt))] };
this.updateOrderUiFields(lookup.order);
lookup.project = {
fields: this.lookupFields
};
return lookup;
}
protected setupColumns() {
this.gridColumns.push(...[{
prop: nameof<Language>(x => x.code),
sortable: true,
languageName: 'LANGUAGE-LISTING.FIELDS.CODE'
},
{
prop: nameof<Language>(x => x.createdAt),
sortable: true,
languageName: 'LANGUAGE-LISTING.FIELDS.CREATED-AT',
pipe: this.pipeService.getPipe<DataTableDateTimeFormatPipe>(DataTableDateTimeFormatPipe).withFormat('short')
},
{
prop: nameof<Language>(x => x.updatedAt),
sortable: true,
languageName: 'LANGUAGE-LISTING.FIELDS.UPDATED-AT',
pipe: this.pipeService.getPipe<DataTableDateTimeFormatPipe>(DataTableDateTimeFormatPipe).withFormat('short')
},
{
alwaysShown: true,
cellTemplate: this.actions,
maxWidth: 120
}
]);
this.propertiesAvailableForOrder = this.gridColumns.filter(x => x.sortable);
}
//
// Listing Component functions
//
onColumnsChanged(event: ColumnsChangedEvent) {
super.onColumnsChanged(event);
this.onColumnsChangedInternal(event.properties.map(x => x.toString()));
}
private onColumnsChangedInternal(columns: string[]) {
// Here are defined the projection fields that always requested from the api.
const fields = new Set(this.lookupFields);
this.gridColumns.map(x => x.prop)
.filter(x => !columns?.includes(x as string))
.forEach(item => {
fields.delete(item as string)
});
this.lookup.project = { fields: [...fields] };
this.onPageLoad({ offset: 0 } as PageLoadEvent);
}
protected loadListing(): Observable<QueryResult<Language>> {
return this.languageV2Service.query(this.lookup);
}
public deleteType(id: Guid) {
if (id) {
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
data: {
isDeleteConfirmation: true,
message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.DELETE-ITEM'),
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CONFIRM'),
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL')
}
});
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
if (result) {
this.languageV2Service.delete(id).pipe(takeUntil(this._destroyed))
.subscribe(
complete => this.onCallbackSuccess(),
error => this.onCallbackError(error)
);
}
});
}
}
onCallbackSuccess(): void {
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-DELETE'), SnackBarNotificationLevel.Success);
this.ngOnInit();
}
}

View File

@ -11,7 +11,7 @@ import { nameof } from 'ts-simple-nameof';
@Injectable() @Injectable()
export class ReferenceTypeEditorResolver extends BaseEditorResolver { export class ReferenceTypeEditorResolver extends BaseEditorResolver {
constructor(private ReferenceTypeService: ReferenceTypeService, private breadcrumbService: BreadcrumbService) { constructor(private referenceTypeService: ReferenceTypeService, private breadcrumbService: BreadcrumbService) {
super(); super();
} }
@ -81,7 +81,7 @@ export class ReferenceTypeEditorResolver extends BaseEditorResolver {
]; ];
const id = route.paramMap.get('id'); const id = route.paramMap.get('id');
if (id != null) { if (id != null) {
return this.ReferenceTypeService.getSingle(Guid.parse(id), fields).pipe(tap(x => this.breadcrumbService.addIdResolvedValue(x.id?.toString(), x.code)), takeUntil(this._destroyed)); return this.referenceTypeService.getSingle(Guid.parse(id), fields).pipe(tap(x => this.breadcrumbService.addIdResolvedValue(x.id?.toString(), x.code)), takeUntil(this._destroyed));
} }
} }
} }

View File

@ -25,7 +25,7 @@ const routes: Routes = [
permissions: [AppPermission.EditReference] permissions: [AppPermission.EditReference]
}, },
...BreadcrumbService.generateRouteDataConfiguration({ ...BreadcrumbService.generateRouteDataConfiguration({
title: 'BREADCRUMBS.NEW-TENANT' title: 'BREADCRUMBS.NEW-REFERENCE'
}) })
} }
}, },
@ -39,7 +39,7 @@ const routes: Routes = [
}, },
data: { data: {
...BreadcrumbService.generateRouteDataConfiguration({ ...BreadcrumbService.generateRouteDataConfiguration({
title: 'BREADCRUMBS.EDIT-TENANT' title: 'BREADCRUMBS.EDIT-REFERENCE'
}), }),
authContext: { authContext: {
permissions: [AppPermission.EditReference] permissions: [AppPermission.EditReference]

View File

@ -11,7 +11,7 @@ import { nameof } from 'ts-simple-nameof';
@Injectable() @Injectable()
export class TenantEditorResolver extends BaseEditorResolver { export class TenantEditorResolver extends BaseEditorResolver {
constructor(private TenantService: TenantService, private breadcrumbService: BreadcrumbService) { constructor(private tenantService: TenantService, private breadcrumbService: BreadcrumbService) {
super(); super();
} }
@ -53,7 +53,7 @@ export class TenantEditorResolver extends BaseEditorResolver {
const id = route.paramMap.get('id'); const id = route.paramMap.get('id');
if (id != null) { if (id != null) {
return this.TenantService.getSingle(Guid.parse(id), fields).pipe(tap(x => this.breadcrumbService.addIdResolvedValue(x.id?.toString(), x.code)), takeUntil(this._destroyed)); return this.tenantService.getSingle(Guid.parse(id), fields).pipe(tap(x => this.breadcrumbService.addIdResolvedValue(x.id?.toString(), x.code)), takeUntil(this._destroyed));
} }
} }
} }

View File

@ -57,7 +57,7 @@ export const ADMIN_ROUTES: RouteInfo[] = [
{ path: '/reference-type', title: 'SIDE-BAR.REFERENCE-TYPES', icon: 'library_books' }, { path: '/reference-type', title: 'SIDE-BAR.REFERENCE-TYPES', icon: 'library_books' },
{ path: '/tenants', title: 'SIDE-BAR.TENANTS', icon: 'library_books' }, { path: '/tenants', title: 'SIDE-BAR.TENANTS', icon: 'library_books' },
{ path: '/users', title: 'SIDE-BAR.USERS', icon: 'people' }, { path: '/users', title: 'SIDE-BAR.USERS', icon: 'people' },
{ path: '/language-editor', title: 'SIDE-BAR.LANGUAGE-EDITOR', icon: 'language' }, { path: '/languages', title: 'SIDE-BAR.LANGUAGES', icon: 'language' },
{ path: '/supportive-material', title: 'SIDE-BAR.SUPPORTIVE-MATERIAL', icon: 'import_contacts' } { path: '/supportive-material', title: 'SIDE-BAR.SUPPORTIVE-MATERIAL', icon: 'import_contacts' }
]; ];

View File

@ -5,7 +5,7 @@
<div> <div>
<div class ="material"> <div class ="material">
<mat-form-field> <mat-form-field>
<mat-label>Material type</mat-label> <mat-label>{{'SUPPORTIVE-MATERIAL-EDITOR.FIELDS.MATERIAL-TYPE' | translate}}</mat-label>
<mat-select [value] ="selectedMaterial" (selectionChange)="selectedMaterialChanged($event.value)"> <mat-select [value] ="selectedMaterial" (selectionChange)="selectedMaterialChanged($event.value)">
<mat-option *ngFor="let vis of visiblesMaterialsTypes" [value]="vis"> <mat-option *ngFor="let vis of visiblesMaterialsTypes" [value]="vis">
{{vis.name | translate}} {{vis.name | translate}}
@ -15,7 +15,7 @@
</div> </div>
<div class ="lang"> <div class ="lang">
<mat-form-field> <mat-form-field>
<mat-label>Language</mat-label> <mat-label>{{'SUPPORTIVE-MATERIAL-EDITOR.FIELDS.LANGUAGE' | translate}}</mat-label>
<mat-select [value] ="selectedLang" (selectionChange)="selectedLangChanged($event.value)"> <mat-select [value] ="selectedLang" (selectionChange)="selectedLangChanged($event.value)">
<mat-option *ngFor="let vis of visiblesLangTypes" [value]="vis"> <mat-option *ngFor="let vis of visiblesLangTypes" [value]="vis">
{{vis.name | translate}} {{vis.name | translate}}
@ -48,7 +48,7 @@
}" formControlName="html"></editor> }" formControlName="html"></editor>
</mat-card-content> </mat-card-content>
</mat-card> </mat-card>
<button mat-fab class="mat-fab-bottom-right save-btn" matTooltip="{{'GUIDE.SAVE' | translate}}" type="submit"> <button mat-fab class="mat-fab-bottom-right save-btn" matTooltip="{{'SUPPORTIVE-MATERIAL-EDITOR.ACTIONS.SAVE' | translate}}" type="submit">
<mat-icon class="mat-24">save</mat-icon> <mat-icon class="mat-24">save</mat-icon>
</button> </button>
</div> </div>

View File

@ -242,10 +242,18 @@
"EDIT-DMP-BLUEPRINT": "Edit", "EDIT-DMP-BLUEPRINT": "Edit",
"NEW-DESCRIPTION-TEMPLATES": "New", "NEW-DESCRIPTION-TEMPLATES": "New",
"EDIT-DESCRIPTION-TEMPLATES": "Edit", "EDIT-DESCRIPTION-TEMPLATES": "Edit",
"REFERENCE-TYPES":"Reference Types",
"NEW-REFERENCE-TYPE": "New", "NEW-REFERENCE-TYPE": "New",
"EDIT-REFERENCE-TYPE": "Edit", "EDIT-REFERENCE-TYPE": "Edit",
"TENANTS":"Tenants",
"NEW-TENANT": "New", "NEW-TENANT": "New",
"EDIT-TENANT": "Edit" "EDIT-TENANT": "Edit",
"REFERENCES":"References",
"NEW-REFERENCE": "New",
"EDIT-REFERENCE": "Edit",
"LANGUAGES": "Languages",
"NEW-LANGUAGE": "New",
"EDIT-LANGUAGE": "Edit"
}, },
"COOKIE": { "COOKIE": {
"MESSAGE": "This website uses cookies to enhance the user experience.", "MESSAGE": "This website uses cookies to enhance the user experience.",
@ -342,7 +350,8 @@
"SUPPORTIVE-MATERIAL": "Supportive Material", "SUPPORTIVE-MATERIAL": "Supportive Material",
"REFERENCE-TYPES":"Reference Types", "REFERENCE-TYPES":"Reference Types",
"TENANTS": "Tenants", "TENANTS": "Tenants",
"REFERENCES": "References" "REFERENCES": "References",
"LANGUAGES": "Languages"
}, },
"DESCRIPTION-TEMPLATE-EDITOR": { "DESCRIPTION-TEMPLATE-EDITOR": {
"TITLE": { "TITLE": {
@ -1139,6 +1148,60 @@
"SUCCESSFUL-DELETE": "Successful Delete", "SUCCESSFUL-DELETE": "Successful Delete",
"UNSUCCESSFUL-DELETE": "This item could not be deleted." "UNSUCCESSFUL-DELETE": "This item could not be deleted."
}, },
"LANGUAGE-LISTING": {
"TITLE": "Languages",
"CREATE": "Create Language",
"FIELDS": {
"CODE": "Code",
"UPDATED-AT": "Updated",
"CREATED-AT": "Created"
},
"FILTER": {
"TITLE": "Filters",
"IS-ACTIVE": "Is Active",
"CANCEL": "Cancel",
"APPLY-FILTERS": "Apply filters"
},
"CONFIRM-DELETE-DIALOG": {
"MESSAGE": "Would you like to delete this Language?",
"CONFIRM-BUTTON": "Yes, delete",
"CANCEL-BUTTON": "No"
},
"ACTIONS": {
"DELETE": "Delete",
"EDIT": "Edit"
},
"SUCCESSFUL-DELETE": "Successful Delete",
"UNSUCCESSFUL-DELETE": "This item could not be deleted."
},
"SUPPORTIVE-MATERIAL-EDITOR": {
"FIELDS": {
"MATERIAL-TYPE": "Material Type",
"LANGUAGE": "Language"
},
"ACTIONS": {
"SAVE": "Save",
"CANCEL": "Cancel",
"DELETE": "Delete"
}
},
"LANGUAGE-EDITOR": {
"NEW": "New Language",
"FIELDS": {
"CODE": "Code",
"PAYLOAD": "Payload"
},
"ACTIONS": {
"SAVE": "Save",
"CANCEL": "Cancel",
"DELETE": "Delete"
},
"CONFIRM-DELETE-DIALOG": {
"MESSAGE": "Would you like to delete this Language?",
"CONFIRM-BUTTON": "Yes, delete",
"CANCEL-BUTTON": "No"
}
},
"DATASET-UPLOAD": { "DATASET-UPLOAD": {
"TITLE": "Import Dataset", "TITLE": "Import Dataset",
"UPLOAD-BUTTON": "Upload", "UPLOAD-BUTTON": "Upload",
@ -1933,7 +1996,18 @@
"REFERENCE-TYPE":{ "REFERENCE-TYPE":{
"TAXONOMY": "Taxonomy", "TAXONOMY": "Taxonomy",
"LICENCE": "License", "LICENCE": "License",
"ORGANISATION": "Organization" "PUBLICATION": "Publication",
"JOURNAL": "Journal",
"PUB-REPOSITORY": "Publication Repository",
"DATA-REPOSITORY": "Data Repository",
"REGISTRY": "Registry",
"SERVICE": "Service",
"PROJECT": "Project",
"FUNDER": "Funder",
"DATASET": "Dataset",
"ORGANISATION": "Organization",
"GRANT": "Grant",
"RESEARCHER": "Researcher"
}, },
"REFERENCE-SOURCE-TYPE":{ "REFERENCE-SOURCE-TYPE":{
"INTERNAL": "Internal", "INTERNAL": "Internal",