Skip to content

Commit

Permalink
Services and store for favourite app from waltz-icon
Browse files Browse the repository at this point in the history
#CTCTOWALTZ-1858
finos#4876
  • Loading branch information
jessica-woodland-scott-db committed Jul 2, 2020
1 parent 828cf74 commit 4d3990a
Show file tree
Hide file tree
Showing 10 changed files with 356 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ public List<AppGroup> findPrivateGroupsByOwner(String userId) {
}


public AppGroup findFavouritesGroupByOwner(String userId) {
SelectConditionStep<Record1<Long>> groupIds = getPrivateGroupIdByOwner(userId);

return dsl.select(APPLICATION_GROUP.fields())
.from(APPLICATION_GROUP)
.where(APPLICATION_GROUP.ID.in(groupIds)
.and(APPLICATION_GROUP.KIND.eq(AppGroupKind.PRIVATE.name())
.and(notRemoved)
.and(APPLICATION_GROUP.IS_FAVOURITE_GROUP.isTrue())))
.fetchOne(TO_DOMAIN);
}


public List<AppGroup> findRelatedByApplicationId(long appId, String username) {

SelectConditionStep<Record1<Long>> groupsFromAppGroupEntry = dsl
Expand Down Expand Up @@ -229,6 +242,8 @@ public Long insert(AppGroup appGroup) {
.set(APPLICATION_GROUP.DESCRIPTION, appGroup.description())
.set(APPLICATION_GROUP.NAME, appGroup.name())
.set(APPLICATION_GROUP.KIND, appGroup.appGroupKind().name())
.set(APPLICATION_GROUP.IS_REMOVED, appGroup.isRemoved())
.set(APPLICATION_GROUP.IS_FAVOURITE_GROUP, appGroup.isFavouriteGroup())
.returning(APPLICATION_GROUP.ID)
.fetchOne()
.getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,17 @@ public int[] addApplications(long groupId, List<Long> applicationIds) {
public int removeApplication(long groupId, long applicationId) {
return dsl.delete(APPLICATION_GROUP_ENTRY)
.where(APPLICATION_GROUP_ENTRY.GROUP_ID.eq(groupId))
.and(APPLICATION_GROUP_ENTRY.APPLICATION_ID.eq(applicationId))
.and(APPLICATION_GROUP_ENTRY.APPLICATION_ID.eq(applicationId)
.and(APPLICATION_GROUP_ENTRY.IS_READONLY.isFalse()))
.execute();
}


public int removeApplications(long groupId, List<Long> applicationIds) {
return dsl.delete(APPLICATION_GROUP_ENTRY)
.where(APPLICATION_GROUP_ENTRY.GROUP_ID.eq(groupId))
.and(APPLICATION_GROUP_ENTRY.APPLICATION_ID.in(applicationIds))
.and(APPLICATION_GROUP_ENTRY.APPLICATION_ID.in(applicationIds)
.and(APPLICATION_GROUP_ENTRY.IS_READONLY.isFalse()))
.execute();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,30 @@

package com.khartec.waltz.jobs.harness;

import com.khartec.waltz.data.application.ApplicationDao;
import com.khartec.waltz.common.exception.InsufficientPrivelegeException;
import com.khartec.waltz.data.application.ApplicationIdSelectorFactory;
import com.khartec.waltz.model.EntityKind;
import com.khartec.waltz.model.EntityReference;
import com.khartec.waltz.model.application.Application;
import com.khartec.waltz.model.app_group.AppGroupEntry;
import com.khartec.waltz.service.DIConfiguration;
import com.khartec.waltz.service.app_group.FavouritesService;
import org.jooq.DSLContext;
import org.jooq.Record1;
import org.jooq.Select;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.List;

import static com.khartec.waltz.model.EntityReference.mkRef;
import static com.khartec.waltz.model.IdSelectionOptions.mkOpts;
import java.util.Collection;


public class AppGroupHarness {

public static void main(String[] args) {
public static void main(String[] args) throws InsufficientPrivelegeException {
System.out.println("--- start");

ApplicationIdSelectorFactory appSelectorFactory = new ApplicationIdSelectorFactory();

AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
DSLContext dsl = ctx.getBean(DSLContext.class);
ApplicationDao applicationDao = ctx.getBean(ApplicationDao.class);

EntityReference grp5 = mkRef(EntityKind.APP_GROUP, 5);
Select<Record1<Long>> selector = appSelectorFactory.apply(mkOpts(grp5));
FavouritesService service = ctx.getBean(FavouritesService.class);

System.out.println(dsl.render(selector));
List<Application> apps = applicationDao.findByAppIdSelector(selector);

System.out.println(apps.size());
Collection<AppGroupEntry> appGroupEntries = service.addApplication("jessica.woodland-scott@db.com", 15792);

System.out.println("--- done");



}

}
3 changes: 2 additions & 1 deletion waltz-ng/client/app-groups/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Routes from './routes';
import AppGroupList from './directives/app-group-list';
import AppGroupListSection from './directives/app-group-list-section';
import AppGroupAppSelectionList from './directives/app-group-app-selection-list';
import FavouritesStore from "./services/favourites-store";


export default () => {
Expand All @@ -44,7 +45,7 @@ export default () => {
SubscriptionButtons,
RelatedAppGroupsSection ]);

registerStores(module, [ AppGroupStore ]);
registerStores(module, [ AppGroupStore, FavouritesStore ]);

return module.name;

Expand Down
73 changes: 73 additions & 0 deletions waltz-ng/client/app-groups/services/favourites-store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Waltz - Enterprise Architecture
* Copyright (C) 2016, 2017, 2018, 2019 Waltz open source project
* See README.md for more information
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific
*
*/

export function store($http, BaseApiUrl) {

const BASE = `${BaseApiUrl}/favourites`;

const getFavouritesGroupEntries = () => $http
.get(`${BASE}/entries`)
.then(result => result.data);

const addApplication = (applicationId) => $http
.post(`${BASE}/application/${applicationId}`)
.then(result => result.data);

const removeApplication = (applicationId) => $http
.delete(`${BASE}/application/${applicationId}`)
.then(result => result.data);

return {
getFavouritesGroupEntries,
addApplication,
removeApplication
};
}


store.$inject = [
'$http',
'BaseApiUrl'
];


const serviceName = "FavouritesStore";


export const FavouritesStore_API = {
getFavouritesGroupEntries: {
serviceName,
serviceFnName: 'getFavouritesGroupEntries',
description: 'fetches application entries for favourites group'
},
addApplication: {
serviceName,
serviceFnName: 'addApplication',
description: 'executes addApplication'
},
removeApplication: {
serviceName,
serviceFnName: 'removeApplication',
description: 'executes removeApplication'
}
};

export default {
serviceName,
store
}
13 changes: 13 additions & 0 deletions waltz-ng/client/applications/components/overview/app-overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@
ui-sref="main.app.edit ({id: $ctrl.app.id})">
Edit
</a>
<waltz-icon name="bookmark-o"
size="2x"
class="clickable small"
ng-if="!$ctrl.isFavourite"
ng-click="$ctrl.addFavouriteApplication()">
</waltz-icon>
<waltz-icon name="bookmark"
size="2x"
class="clickable small"
ng-class="{'text-muted': $ctrl.isReadOnly}"
ng-if="$ctrl.isFavourite"
ng-click="$ctrl.removeFavouriteApplication()">
</waltz-icon>
</waltz-section-actions>
<div class="waltz-display-section">
<div class="row">
Expand Down
33 changes: 31 additions & 2 deletions waltz-ng/client/applications/components/overview/app-overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function controller($state, serviceBroker, notification) {
return serviceBroker
.loadAppData(
CORE_API.AppGroupStore.findRelatedByEntityRef,
[vm.parentEntityRef])
[vm.parentEntityRef], {force: true})
.then(r => {
vm.appGroups = _.orderBy(r.data, ['appGroupKind', 'name'], ['desc', 'asc']);

Expand All @@ -102,7 +102,13 @@ function controller($state, serviceBroker, notification) {
} else {
vm.appGroupsToDisplay = _.filter(vm.appGroups, r => vm.appGroups.indexOf(r) < 10);
}
});

vm.isFavourite = _.find(vm.appGroups, d => d.isFavouriteGroup);

serviceBroker
.loadViewData(CORE_API.FavouritesStore.getFavouritesGroupEntries)
.then(r => vm.isReadOnly = _.get(_.find(r.data, d => d.id === vm.parentEntityRef.id), 'isReadOnly', false))
})
}

vm.$onInit = () => {
Expand Down Expand Up @@ -140,6 +146,29 @@ function controller($state, serviceBroker, notification) {
vm.toggleAppGroupDisplay = () => {
vm.showAllAppGroups = !vm.showAllAppGroups;
loadAppGroups();
};

vm.addFavouriteApplication = () => {
serviceBroker
.execute(CORE_API.FavouritesStore.addApplication, [vm.parentEntityRef.id])
.then(() => {
notification.success("Added to favourites");
loadAppGroups()
})
};

vm.removeFavouriteApplication = () => {

if (vm.isReadOnly){
notification.error("This app is a direct involvement and cannot be removed from favorites")
} else {
serviceBroker
.execute(CORE_API.FavouritesStore.removeApplication, [vm.parentEntityRef.id])
.then(() => {
notification.info("Removed from favourites");
loadAppGroups()
})
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions waltz-ng/client/common/services/core-api-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {EnumValueStore_API as EnumValueStore} from "../../enum-value/services/en
import {EntitySvgDiagramStore_API as EntitySvgDiagramStore} from "../../entity-svg-diagram/services/entity-svg-diagram-store";
import {ExternalIdentifierStore_API as ExternalIdentifierStore} from "../../external-identifier/services/external-identifier-store"
import {FacetStore_API as FacetStore} from "../../facet/services/facet-store";
import {FavouritesStore_API as FavouritesStore} from "../../app-groups/services/favourites-store";
import {FlowDiagramStore_API as FlowDiagramStore} from "../../flow-diagram/services/flow-diagram-store";
import {FlowDiagramAnnotationStore_API as FlowDiagramAnnotationStore} from "../../flow-diagram/services/flow-diagram-annotation-store";
import {FlowDiagramEntityStore_API as FlowDiagramEntityStore} from "../../flow-diagram/services/flow-diagram-entity-store";
Expand Down Expand Up @@ -138,6 +139,7 @@ export const CORE_API = {
EnumValueStore,
ExternalIdentifierStore,
FacetStore,
FavouritesStore,
FlowDiagramStore,
FlowDiagramAnnotationStore,
FlowDiagramEntityStore,
Expand Down
Loading

0 comments on commit 4d3990a

Please sign in to comment.