Skip to content

Commit

Permalink
Merge pull request #158 from FlickerSoul/dev
Browse files Browse the repository at this point in the history
Graph API change
  • Loading branch information
FlickerSoul authored Mar 1, 2021
2 parents 0b15187 + 0d16f3b commit 6263bfb
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 25 deletions.
7 changes: 4 additions & 3 deletions backend/bundle/GraphObjects/Edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Edge(Comparable, HasProperty, Stylable):

default_directed_styles = []

def __init__(self, identity, node_pair: NodeTuple, name=None, directed=False,
def __init__(self, identity, node_pair: Union[NodeTuple, Tuple[Node, Node]], name=None, directed=False,
styles: Union[str, Iterable[Mapping]] = (), classes: Iterable[str] = (),
add_default_styles=False, add_default_classes=False):
"""
Expand All @@ -34,9 +34,10 @@ def __init__(self, identity, node_pair: NodeTuple, name=None, directed=False,
self, [*styles, *(self.default_directed_styles if directed else ())], classes,
add_default_styles=add_default_styles, add_default_classes=add_default_classes
)

if isinstance(node_pair, Tuple) and all(isinstance(node, Node) for node in node_pair):
if isinstance(node_pair, NodeTuple):
self.node_pair: NodeTuple = node_pair
if isinstance(node_pair, Tuple) and all(isinstance(node, Node) for node in node_pair):
self.node_pair: NodeTuple = NodeTuple(*node_pair)
else:
raise KeyError('%s is not a tuple or contains non-node element' % str(node_pair))
self.directed: bool = directed
Expand Down
34 changes: 24 additions & 10 deletions backend/bundle/GraphObjects/Graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .Edge import Edge, EdgeSet, MutableEdgeSet, NodeTuple, EdgeIDTuple

import json
from typing import Iterable, Union, Optional, Mapping, Type, TypeVar, Generic
from typing import Iterable, Union, Optional, Mapping, Type, TypeVar, Generic, Tuple
from enum import Enum


Expand Down Expand Up @@ -207,20 +207,34 @@ def __init__(self, nodes: Iterable[Node] = (), edges: Iterable[Edge] = ()):
super().__init__(nodes, edges, node_container=MutableNodeSet, edge_container=MutableEdgeSet)

def add_node(self, identity: Union[str, Node] = None,
styles: Union[str, Iterable[Mapping]] = (), classes: Iterable[str] = ()) -> Node:
node = Node.return_node(identity=identity, styles=styles, classes=classes)
styles: Union[str, Iterable[Mapping]] = (), classes: Iterable[str] = (),
add_default_styles: bool = False, add_default_classes: bool = False) -> Node:
node = Node.return_node(identity=identity, styles=styles, classes=classes,
add_default_classes=add_default_classes, add_default_styles=add_default_styles)
self.nodes.add_node(node)
return node

def add_edge(self,
identity: str = None,
edge: Union[Edge, NodeTuple, EdgeIDTuple] = (),
styles: Union[str, Iterable[Mapping]] = (), classes: Iterable[str] = ()) -> Optional[Edge]:
edge = Edge.return_edge(identity, edge, styles, classes)

# TODO think about it
for node in edge:
self.add_node(node)
edge: Union[Edge, NodeTuple, Tuple[Node, Node], EdgeIDTuple, Tuple[str, str]] = (),
styles: Union[str, Iterable[Mapping]] = (), classes: Iterable[str] = (),
add_default_styles: bool = False, add_default_classes: bool = False) -> Optional[Edge]:
if isinstance(edge, Edge):
n1, n2 = edge.get_nodes()
if not self.has_node(n1) and not self.has_node(n2):
raise ValueError(f'You need to add nodes first. Unresolved node in {edge}')
edge = edge
elif isinstance(edge, NodeTuple) or (isinstance(edge, Tuple) and all(isinstance(ele, Node) for ele in edge)):
if not all(self.has_node(ele) for ele in edge):
raise ValueError(f'You need to add nodes first. Unresolved node in {edge}')
edge = Edge(identity, edge, styles=styles, classes=classes,
add_default_styles=add_default_styles, add_default_classes=add_default_classes)
elif isinstance(edge, EdgeIDTuple) or (isinstance(edge, Tuple) and all(isinstance(ele, str) for ele in edge)):
node_pair = self.get_node(edge[0]), self.get_node(edge[1])
edge = Edge(identity, node_pair, styles=styles, classes=classes,
add_default_styles=add_default_styles, add_default_classes=add_default_classes)
else:
raise TypeError('Invalid Type')

self.edges.add_edge(edge)
return edge
Expand Down
6 changes: 4 additions & 2 deletions backend/bundle/GraphObjects/Node.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ def __repr__(self):
return self.__str__()

@staticmethod
def return_node(identity: Union[str, Node], styles: Iterable[Mapping] = (), classes: Iterable[str] = ()):
def return_node(identity: Union[str, Node], styles: Iterable[Mapping] = (), classes: Iterable[str] = (),
add_default_styles: bool = False, add_default_classes: bool = False):
if isinstance(identity, str):
return Node(identity=identity, styles=styles, classes=classes)
return Node(identity=identity, styles=styles, classes=classes,
add_default_styles=add_default_styles, add_default_classes=add_default_classes)
elif isinstance(identity, Node):
return identity
else:
Expand Down
2 changes: 1 addition & 1 deletion backend/bundle/server_utils/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
REQUEST_GRAPH_NAME: str = 'graph'

REQUEST_VERSION_NAME: str = 'version'
VERSION: str = '0.2.5'
VERSION: str = '0.2.6'

SERVER_LOG = None

Expand Down
2 changes: 1 addition & 1 deletion backend/bundle/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def read_file(filename):

setuptools.setup(
name="bundle",
version="0.2.5",
version="0.2.6",
packages=setuptools.find_packages(exclude=['tests*']),
author="Heyuan Zeng",
author_email="[email protected]",
Expand Down
42 changes: 41 additions & 1 deletion backend/bundle/tests/graph_tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,50 @@ def test_mutable_graph_add_node(mutable_graph: MutableGraph):


def test_mutable_graph_add_edge(mutable_graph: MutableGraph):
n1 = mutable_graph.add_node('n1')
n2 = mutable_graph.add_node('n2')

mutable_graph.add_edge('1', ('n1', 'n2'))
assert Edge('1', (Node('n1'), Node('n2'))) in mutable_graph
assert mutable_graph.has_edge('1')
recorded_edge = mutable_graph.get_edge('1')
assert recorded_edge.node_pair[0].identity == 'n1'
assert recorded_edge.node_pair[1].identity == 'n2'
# assert Edge('1', (Node('n1'), Node('n2'))) in mutable_graph
assert len(mutable_graph.E) == 1

mutable_graph.add_edge('2', (n1, n2))
assert mutable_graph.has_edge('2')
recorded_edge = mutable_graph.get_edge('2')
assert recorded_edge.node_pair[0].identity == 'n1'
assert recorded_edge.node_pair[1].identity == 'n2'
# assert Edge('1', (Node('n1'), Node('n2'))) in mutable_graph
assert len(mutable_graph.E) == 2

mutable_graph.add_edge(edge=Edge('3', (n1, n2)))
assert mutable_graph.has_edge('3')
recorded_edge = mutable_graph.get_edge('3')
assert recorded_edge.node_pair[0].identity == 'n1'
assert recorded_edge.node_pair[1].identity == 'n2'
# assert Edge('1', (Node('n1'), Node('n2'))) in mutable_graph
assert len(mutable_graph.E) == 3


def test_unresolvable_edge(mutable_graph: MutableGraph):
n1 = Node('n1')
n2 = Node('n2')
edge = Edge('n1->n2', (n1, n2))
with pytest.raises(ValueError):
mutable_graph.add_edge(edge=edge)

with pytest.raises(ValueError):
mutable_graph.add_edge('n1->n2', (n1, n2))

with pytest.raises(Exception):
mutable_graph.add_edge('n1->n2', ('n1', 'n2'))

with pytest.raises(TypeError):
mutable_graph.add_edge('n1->n2', (True, False))


def test_mutable_graph_delete_node_no_conflict(mutable_graph: MutableGraph):
node_num = 20
Expand Down
2 changes: 1 addition & 1 deletion backend/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def read_file(filename):

setuptools.setup(
name="Graphery Servers",
version="0.25.7",
version="0.25.8",
packages=setuptools.find_packages(exclude=['tests*']),
install_requires=read_file('requirements.txt'),
author="Heyuan Zeng",
Expand Down
2 changes: 1 addition & 1 deletion graphery/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphery",
"version": "0.25.7",
"version": "0.25.8",
"private": true,
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion graphery/src/components/framework/Footer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</div>
<div class="right-section">
<div>
2020 ©
2020 - 2021 ©
<router-link :to="{ name: 'About' }">
Graphery
</router-link>
Expand Down
31 changes: 28 additions & 3 deletions graphery/src/components/framework/TOSPopup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,41 @@
import { Notify } from 'quasar';
export default {
data() {
return {
tosVersion_: '0.0.1',
};
},
computed: {
isShowingTOS() {
return !(
this.$store.state.settings.tosAgreeAndDoNotShowAgain &&
this.$store.state.settings.tosVersion === this.tosVersion_
);
},
selectMessage() {
if (this.$store.state.settings.tosVersion === this.tosVersion_) {
return 'Cookies helps us improve your experience';
} else {
return '[TOS Updated] Cookies helps us improve your experience';
}
},
},
methods: {
jumpToTOS() {
this.$router.push({ name: 'TOS' });
},
agreeTos() {
this.$store.commit('settings/CHANGE_TOS_AGREE_AND_NOT_SHOW', true);
this.$store.commit('settings/CHANGE_TOS_VERSION', this.tosVersion_);
},
showTOSTerms() {
if (!this.$store.state.settings.tosAgreeAndDoNotShowAgain) {
if (this.isShowingTOS) {
Notify.create({
type: 'gdpr',
caption:
'By continuing to access Graphery, you agree to the terms of service and privacy notice',
message: 'Cookies helps us improve your experience',
message: this.selectMessage,
group: false,
timeout: 0,
multiLine: true,
Expand All @@ -26,10 +47,14 @@
handler: this.jumpToTOS,
},
{
label: 'Close',
label: 'Never Show Again',
color: 'white',
handler: this.agreeTos,
},
{
label: 'Close',
color: 'white',
},
],
});
}
Expand Down
2 changes: 1 addition & 1 deletion graphery/src/services/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ def main() -> None:
# https://github.com/FlickerSoul/Graphery/tree/master/backend/bundle#readme
`;

export const localServerTargetVersion = '0.2.5';
export const localServerTargetVersion = '0.2.6';
4 changes: 4 additions & 0 deletions graphery/src/store/modules/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const state: SettingState = {

// invisible states
tosAgreeAndDoNotShowAgain: false,
tosVersion: null,
};

const mutations: MutationTree<SettingState> = {
Expand Down Expand Up @@ -87,6 +88,9 @@ const mutations: MutationTree<SettingState> = {
CHANGE_TOS_AGREE_AND_NOT_SHOW(state, value: boolean) {
state.tosAgreeAndDoNotShowAgain = value;
},
CHANGE_TOS_VERSION(state, value: string) {
state.tosVersion = value;
},
};

const actions: ActionTree<SettingState, RootState> = {
Expand Down
1 change: 1 addition & 0 deletions graphery/src/store/states/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export interface SettingInfos {

// invisible state
tosAgreeAndDoNotShowAgain: boolean;
tosVersion: string | null;
}

export interface SettingState extends SettingInfos {
Expand Down

0 comments on commit 6263bfb

Please sign in to comment.