Exemplo n.º 1
0
        private void generateTemplate()
        {
            DynamicUIFactory            dynamicUIFactory   = new DynamicUIFactory();
            Dictionary <string, string> templateDictionary = TemplateDictionary.Instance();
            JObject template = JObject.Parse((string)templateDictionary[templateArrayNumber]);
            bool    required, multiselect;
            string  label, fieldname;

            templateTitle   = (string)template["data"]["templatetitle"];
            formtemplateid  = (string)template["data"]["formtemplateid"];
            templateversion = (string)template["data"]["templateversion"];
            Title           = templateTitle;
            JArray fieldsets = (JArray)template["data"]["fieldsets"];

            for (int i = 0; i < fieldsets.Count; i++)
            {
                /*
                 * FIELDSETS
                 */

                int fieldsetDevicetype = (int)fieldsets[i]["devicetype"];

                //Kigger om fieldsettet skal benyttes i mobilapplikationen. OBS, fremadrettet skal der også tages forbehold for accessread og accessedit
                if (fieldsetDevicetype == 1)
                {
                    //Tilføjer feltsætnavn til dynamicUIList
                    string            fieldsetTitle   = (string)fieldsets[i]["fieldsettitle"];
                    AbstractDynamicUI guiElementLabel = dynamicUIFactory.getDynamicUI("label");
                    guiElementLabel.setLabel(fieldsetTitle);
                    dynamicUIList.Add(guiElementLabel);


                    JArray fields = (JArray)fieldsets[i]["fields"];
                    for (int ii = 0; ii < fields.Count; ii++)
                    {
                        /*
                         * FIELDS
                         */
                        Dictionary <string, string> valueListDictionary = new Dictionary <string, string>();
                        int fieldDevicetype = (int)fields[ii]["devicetype"];
                        if (fieldDevicetype == 1)
                        {
                            required    = (bool)fields[ii]["required"];
                            multiselect = (bool)fields[ii]["multiselect"];
                            label       = (string)fields[ii]["label"];
                            fieldname   = (string)fields[ii]["fieldname"];

                            //Går igennem valuelist
                            string sourcetype = (string)fields[ii]["sourcetype"];
                            if (sourcetype.Equals("list"))
                            {
                                JArray valueList = (JArray)fields[ii]["valuelist"];
                                for (int iii = 0; iii < valueList.Count; iii++)
                                {
                                    string valueListID   = (string)valueList[iii]["id"];
                                    string valueListName = (string)valueList[iii]["name"];
                                    valueListDictionary.Add(valueListID, valueListName);
                                }
                            }

                            //Gets keywords from keywordalias
                            if (sourcetype.Equals("keyword"))
                            {
                                string json        = Application.Current.Properties["KEYWORDS"] as string;
                                JArray keywordList = JArray.Parse(json);
                                //JArray keywordList = Application.Current.Properties["KEYWORDS"] as JArray;
                                string keyword = (string)fields[ii]["keywordalias"];

                                for (int iiii = 0; iiii < keywordList.Count; iiii++)
                                {
                                    string alias = (string)keywordList[iiii]["alias"];
                                    if (alias.Equals(keyword))
                                    {
                                        JArray valuesArray = (JArray)keywordList[iiii]["valuesarray"];
                                        foreach (string items in valuesArray)
                                        {
                                            if (!valueListDictionary.ContainsKey(items))
                                            {
                                                valueListDictionary.Add(items, items); //OBS Fejl med samme itemkey
                                            }
                                        }
                                    }
                                }
                            }

                            //Gets the type og GUI element
                            string            type       = (string)fields[ii]["type"];
                            AbstractDynamicUI guiElement = dynamicUIFactory.getDynamicUI(type);

                            if (guiElement != null)
                            {
                                //Sets the variables of the GUI element
                                guiElement.setRequired(required);
                                guiElement.setMultiSelect(multiselect);
                                guiElement.setID(fieldname);
                                guiElement.setLabel(label);

                                //Sets the valuelist
                                if (valueListDictionary.Any())
                                {
                                    guiElement.setValueList(valueListDictionary);
                                }

                                //Adds the GUI element to a list
                                dynamicUIList.Add(guiElement);
                            }
                        }
                    }
                }
            }

            if (dynamicUIList.Any())
            {
                generateUIFromList();
            }
        }
Exemplo n.º 2
0
        private void loadIcons()
        {
            //Loads icon from TEMPLATE_DICTIONARY in application properties if it already exits.
            if (Application.Current.Properties.ContainsKey("TEMPLATE_DICTIONARY"))
            {
                templateDictionary = JsonConvert.DeserializeObject <Dictionary <string, string> >(Application.Current.Properties["TEMPLATE_DICTIONARY"] as string);
                TemplateDictionary.setDictionary(templateDictionary);
            }
            else
            {
                templateDictionary = TemplateDictionary.Instance();
                string templateJSON = JsonConvert.SerializeObject(templateDictionary, Formatting.Indented);
                Application.Current.Properties["TEMPLATE_DICTIONARY"] = templateJSON;
                Application.Current.SavePropertiesAsync();
            }

            int left = 0;
            int top  = 0;

            for (int i = 0; i < templateDictionary.Count; i++)
            {
                StackLayout stackLayout = new StackLayout {
                    Orientation = StackOrientation.Vertical, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Start
                };
                Label label = new Label();

                //Get iconURL
                string  templateString = (string)templateDictionary[i.ToString()];
                JObject templateJSON   = JObject.Parse(templateString);
                string  iconURL        = (string)templateJSON["templateiconurl"];

                //Set image to iconURL
                var imageSource = new UriImageSource {
                    Uri = new Uri("https://e-dok.rm.dk/" + iconURL)
                };
                Image iconImage = new Image();
                iconImage.Source        = imageSource;
                iconImage.ClassId       = i.ToString();
                iconImage.HeightRequest = 100;
                iconImage.WidthRequest  = 100;
                label.Text              = (string)templateJSON["data"]["templatetitle"];
                label.TextColor         = Color.Black;
                label.HorizontalOptions = LayoutOptions.Center;

                stackLayout.Children.Add(iconImage);
                stackLayout.Children.Add(label);

                frame = new Frame {
                    Content = stackLayout, Margin = new Thickness(2, 2, 2, 2), ClassId = i.ToString(), StyleId = (string)templateJSON["data"]["templatetitle"]
                };
                frame.HasShadow = true;

                //Adds onTap event
                var tapGestureRecognizer = new TapGestureRecognizer();
                tapGestureRecognizer.Tapped += TapGestureRecognizer_Tapped;
                frame.GestureRecognizers.Add(tapGestureRecognizer);

                imageList.Add(frame);
            }

            //Sort alphabetically
            List <Frame> sortedFrameList = imageList.OrderBy(o => o.StyleId).ToList();

            for (int i = 0; i < sortedFrameList.Count; i++)
            {
                frame = sortedFrameList[i];
                MainLayout.Children.Add(frame, left, top);
                left++;

                if (left > 1)
                {
                    top++;
                    left = 0;
                }
            }

            Content = ParentLayout;
        }