Example #1
0
        /// <summary>
        /// Prepares drag system by setting initial drag object values
        /// </summary>
        /// <param name="item">The item</param>
        /// <param name="parent">The parent category</param>
        public void SetTargetInCategory(IClientPlanetListItem item,
                                        ChannelListCategoryComponent parent)
        {
            currentDragIndex = 0;

            if (parent != null)
            {
                currentDragIndex = parent.GetIndex(item);
            }

            currentDragParentPlanet   = null;
            currentDragParentCategory = parent;
            currentDragItem           = item;
        }
Example #2
0
        public async Task OnItemDropOnChatChannel(ChannelListChatChannelComponent target)
        {
            if (target == null)
            {
                return;
            }

            var oldIndex = 0;

            if (currentDragParentCategory != null)
            {
                oldIndex = currentDragParentCategory.GetIndex(currentDragItem);
            }
            var newIndex = target.ParentCategory.GetIndex(target.Channel);

            // Remove from old list
            if (currentDragParentCategory != null)
            {
                currentDragParentCategory.ItemList.RemoveAt(oldIndex);
            }
            // Insert into new list at correct position
            target.ParentCategory.ItemList.Insert(newIndex, currentDragItem);
            currentDragItem.Parent_Id = target.ParentCategory.Category.Id;

            HttpResponseMessage        response  = null;
            List <CategoryContentData> orderData = null;

            // Categories are not the same
            //if (currentDragParentCategory.Category.Id !=
            //    target.ParentCategory.Category.Id)
            //{
            // Update the target's category

            // Create order data
            orderData = new List <CategoryContentData>();

            ushort pos = 0;

            foreach (var item in target.ParentCategory.ItemList)
            {
                Console.WriteLine($"{item.Id} at {pos}");

                orderData.Add(
                    new CategoryContentData()
                {
                    Id       = item.Id,
                    Position = pos,
                    ItemType = item.ItemType
                }
                    );

                pos++;
            }

            response = await ClientUserManager.Http.PostAsJsonAsync($"api/category/{target.ParentCategory.Category.Id}/children/order", orderData);

            Console.WriteLine(await response.Content.ReadAsStringAsync());

            //target.ParentCategory.Refresh();
            //}

            // Update the source category
            //currentDragParentCategory.Refresh();

            Console.WriteLine($"Dropped {currentDragItem.Id} onto {target.Channel.Id} at {newIndex}");
        }