Beispiel #1
0
        public HttpResponseMessage GetBlockPreviewMarkup([FromBody] BlockPreview data)
        {
            var contentType = Services.ContentTypeService.Get(data.ContentTypeAlias);

            var editor = new BlockListPropertyValueConverter(
                _profilingLogger,
                new BlockEditorConverter(_publishedSnapshotAccessor, _publishedModelFactory));

            //This gets the property type for the property on the page, however it only works for the first level block.
            //For blocks within blocks the editor doesn't seem to give us the property type of the 2nd level block anywhere and we need to figure something else out
            //var publishedContentType = new Lazy<IPublishedContentType>(() => _publishedContentTypeFactory.CreateContentType(contentType)).Value;
            //var propertyType = publishedContentType.PropertyTypes.FirstOrDefault(x => x.Alias == data.PropertyAlias);

            //var page = default(IPublishedContent);

            //// If the page is new, then the ID will be zero
            //// NOTE: the page isn't currently used in the block renderer, so I'm not sure if this is needed.
            //if (data.PageId > 0)
            //{
            //    // Get page container node
            //    page = Umbraco.Content(data.PageId);
            //    if (page == null)
            //    {
            //        // If unpublished, then fake PublishedContent
            //        page = new UnpublishedContent(data.PageId, Services, _publishedContentTypeFactory, Current.PropertyEditors);
            //    }
            //}

            //This wont work with multiple levels
            //var converted = editor.ConvertIntermediateToObject(page, propertyType, PropertyCacheLevel.None, data.Value, false) as BlockListModel;

            //This is needed since I can't figure out how to get the property type of the bock in the block renderer (if that's even possible).
            //You can look at the page alias for the first level, but for blocks within bocks, the renderer needs a way to pass this in..
            //Copying the code her is a bad way to fix this, but once this is possible in the core (or someone figures out how to do it), we can remove this.
            var converted = ConvertIntermediateToObjectCustom(null, null, PropertyCacheLevel.None, data.Value, false) as BlockListModel;

            var model = converted[0];
            // Render view
            var partialName = string.Format(ConfigurationManager.AppSettings["BlockTypeGridViewPreviewPath"] ?? "~/Views/Partials/BlockList/Components/{0}.cshtml", model.Content.ContentType.Alias);
            var markup      = Helpers.ViewHelper.RenderPartial(partialName, model, UmbracoContext.HttpContext, UmbracoContext);

            // Return response
            var response = new HttpResponseMessage
            {
                Content = new StringContent(markup ?? string.Empty)
            };

            response.Content.Headers.ContentType = new MediaTypeHeaderValue(MediaTypeNames.Text.Html);

            return(response);
        }
        public HttpResponseMessage GetBlockPreviewMarkup([FromBody] BlockPreview data)
        {
            var contentType          = Services.ContentTypeService.Get(data.ContentTypeAlias);
            var publishedContentType = new Lazy <IPublishedContentType>(() => _publishedContentTypeFactory.CreateContentType(contentType)).Value;
            var propertyType         = publishedContentType.PropertyTypes.FirstOrDefault(x => x.Alias == data.PropertyAlias);

            var editor = new BlockListPropertyValueConverter(
                _profilingLogger,
                new BlockEditorConverter(_publishedSnapshotAccessor, _publishedModelFactory));

            var page = default(IPublishedContent);

            // If the page is new, then the ID will be zero
            if (data.PageId > 0)
            {
                // Get page container node
                page = Umbraco.Content(data.PageId);
                if (page == null)
                {
                    // If unpublished, then fake PublishedContent
                    page = new UnpublishedContent(data.PageId, Services, _publishedContentTypeFactory, Current.PropertyEditors);
                }
            }

            var converted = editor.ConvertIntermediateToObject(page, propertyType, PropertyCacheLevel.None, data.Value, false) as BlockListModel;
            var model     = converted[0];
            // Render view
            var partialName = string.Format(ConfigurationManager.AppSettings["BlockTypeGridViewPreviewPath"] ?? "~/Views/Partials/BlockList/Components/{0}.cshtml", model.Content.ContentType.Alias);
            var markup      = Helpers.ViewHelper.RenderPartial(partialName, model, UmbracoContext.HttpContext, UmbracoContext);

            // Return response
            var response = new HttpResponseMessage
            {
                Content = new StringContent(markup ?? string.Empty)
            };

            response.Content.Headers.ContentType = new MediaTypeHeaderValue(MediaTypeNames.Text.Html);

            return(response);
        }
        public void Update()
        {
            BlockPreview preview = Preview;

            if (preview != null)
            {
                //Find which GameObject is being targeted.
                Transform camera    = Camera.main.transform;
                Vector3   direction = camera.forward;
                if (Physics.Raycast(camera.position, direction, out look))
                {
                    // <<something was hit>>

                    //Apply 'hitError' to the raycast hit.
                    look.point -= direction * hitError;

                    BlockGrid grid = Grid = look.transform.gameObject.GetComponent <BlockGrid>();
                    if (grid)
                    {
                        //There is a grid, so align the block to the grid.
                        preview.transform.position = grid.WorldPoint_to_WorldGrid(look.point);
                        preview.transform.rotation = grid.transform.rotation * Rotation;
                    }
                    else
                    {
                        //There isn't any grid, so just put the preview at the raycast hit.
                        preview.transform.position = look.point;
                    }
                }
                else
                {
                    //Nothing is being targeted so just put the preview at the max distance.
                    Grid       = null;
                    look.point = camera.position + (direction * distance);
                    preview.transform.position = look.point;
                }
            }
        }