Пример #1
0
def creates_new_node(board_id):
    """
    Creates a new node an likit to board id and user id
    """
    typo = request.get_json()['type']
    board = storage.get(Board, board_id)
    user_id = board.user_id
    # print(user_id)
    nodes = load_templates()
    if typo in nodes['nodes'].keys():
        js = request.get_json()
        if 'data' in js.keys():
            n_node = copy_node(board, nodes['nodes'][typo], js['data'])
        else:
            n_node = copy_node(board, nodes['nodes'][typo])
        return Response(
            json.dumps(json.loads(n_node.to_dict())),
            mimetype='application/json', status=200)
    new_node = CustomNode()
    new_node.name = 'New'
    new_node.user_id = user_id
    new_node.board_id = board_id
    if 'whatsapp' in typo:
        new_node.work_type = 'sender'
        new_node.name = typo
    new_node.save()
    nodes = json.loads(board.nodes)
    nodes[new_node.id] = {'x': 20, 'y': 60}
    board.nodes = json.dumps(nodes)
    board.save()
    # template = render_template('node.html',
    # nodes=[json.loads(new_node.to_dict())], )
    return Response(json.dumps(json.loads(new_node.to_dict())),
                    mimetype='application/json', status=200)
Пример #2
0
def create_a_new_board(user_id):
    """
    Creates a new board appended to the user id
    and the returns the id of the new board
    """
    user = storage.get(User, user_id)
    # Create a new Board
    board = Board()
    board.nodes = '{}'
    board.user_id = user_id
    # Create a service inside the board
    d_service = CustomNode()
    # Set the service settings
    d_service.user_id = user_id
    d_service.board_id = board.id
    d_service.type = 'service'
    d_service.work_type = 'process'
    d_service.name = 'Result'
    # store the service in the board
    objects = json.loads(board.nodes)
    objects[d_service.id] = {'x': 100, 'y': 100}
    board.nodes = json.dumps(objects)
    # Save the created instances
    d_service.save()
    board.save()
    return Response(json.dumps({'board_id': board.id}),
                    mimetype='application/json')
Пример #3
0
def copy_node_to_board(node_id, board_id):
    """
    create a new node based on an existin one from other board
    """
    node = storage.get(CustomNode, node_id)
    new_node = CustomNode()
    in_node = json.loads(node.to_dict())
    sample_keys = json.loads(node.to_dict()).keys()
    # print(in_node)
    del in_node['id']
    for key in sample_keys:
        if key in in_node:
            val = in_node[key]
            if type(val) == dict or type(val) == list:
                val = json.dumps(val)
            setattr(new_node, key, val)
    new_node.innodes = json.dumps([])
    new_node.outnodes = json.dumps([])
    new_node.board_id = board_id
    new_node.save()
    board = storage.get(Board, board_id)
    nodes = json.loads(board.nodes)
    nodes[new_node.id] = {'x': 20, 'y': 50}
    board.nodes = json.dumps(nodes)
    board.save()
    return Response('success', status=200)
Пример #4
0
def creates_new_node(board_id):
    """
    Creates a new node an likit to board id and user id
    """
    board = storage.get(Board, board_id)
    user_id = board.user_id
    print(user_id)
    new_node = CustomNode()
    new_node.name = 'New'
    new_node.user_id = user_id
    new_node.board_id = board_id
    new_node.save()
    nodes = json.loads(board.nodes)
    nodes[new_node.id] = {'x': 20, 'y': 60}
    board.nodes = json.dumps(nodes)
    board.save()
    # template = render_template('node.html', nodes=[json.loads(new_node.to_dict())], )
    return Response(json.dumps(json.loads(new_node.to_dict())),
                    mimetype='application/json',
                    status=200)
Пример #5
0
def copy_node(board, node, data=None, complete=False):
    """
    Copy a node
    """
    new_node = CustomNode()
    in_node = node
    # print(in_node)
    del in_node['id']
    sample_keys = in_node.keys()
    for key in sample_keys:
        val = in_node[key]
        if type(val) == dict or type(val) == list:
            val = json.dumps(val)
        setattr(new_node, key, val)
    if complete:
        new_node.innodes = json.dumps(node['innodes'])
        new_node.outnodes = json.dumps(node['outnodes'])
    else:
        new_node.innodes = json.dumps([])
        new_node.outnodes = json.dumps([])
    if data:
        new_node.data = json.dumps(data)
    new_node.analisis_mode = node['analisis_mode']
    new_node.board_id = board.id
    new_node.user_id = board.user_id
    new_node.save()
    nodes = json.loads(board.nodes)
    nodes[new_node.id] = {'x': 20, 'y': 50}
    board.nodes = json.dumps(nodes)
    board.save()
    return new_node
Пример #6
0
def add_node(board_id):
    """
    Append Node from file one by one
    """
    board = storage.get(Board, board_id)
    in_nodes = request.get_json()
    for nod in in_nodes:
        new_node = CustomNode()
        sample_keys = json.loads(new_node.to_dict()).keys()
        try:
            print('the node from the file\n', nod)
        except Exception as e:
            print(e)
        del nod['id']
        for key in sample_keys:
            if key in nod:
                val = nod[key]
                if type(val) == dict or type(val) == list:
                    val = json.dumps(val)
                setattr(new_node, key, val)
        new_node.name = nod['name']
        new_node.color = nod['color']
        new_node.user_id = board.user_id
        new_node.innodes = json.dumps([])
        new_node.outnodes = json.dumps([])
        new_node.board_id = board_id
        new_node.data = json.dumps(nod['data'])
        new_node.work_type = nod['work_type']
        new_node.analisis_mode = nod['analisis_mode']
        new_node.headers = json.dumps(nod['headers'])
        new_node.save()
        nodes = json.loads(board.nodes)
        nodes[new_node.id] = {'x': 20, 'y': 50}
        board.nodes = json.dumps(nodes)
        board.save()
    return Response('success', status=200)
Пример #7
0
            elif chose == 'add_out':
                outnodes = json.loads(node.outnodes)
                value = input('value > ')
                outnodes.append(value)
                node.outnodes = json.dumps(outnodes)
                node.save()
            elif chose == 'add_in':
                innodes = json.loads(node.innodes)
                value = input('value > ')
                innodes.append(value)
                node.innodes = json.dumps(innodes)
                node.save()
            elif chose == 'add_h':
                heads = json.loads(node.headers)
                key = input('key > ')
                value = input('value > ')
                heads[key] = value
                node.headers = json.dumps(heads)
                node.save()
            elif chose == 'back':
                break
    elif chose[0] == 'c':
        new_node = CustomNode()
        name = input('New node name > ')
        new_node.name = name
        print(storage.all(User))
        user_id = input('Node user > ')
        new_node.user_id = user_id
        new_node.save()
        objects = storage.all(CustomNode)