Advertisement
Guest User

Untitled

a guest
Sep 27th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.36 KB | None | 0 0
  1. *** MainViewModel.cs ***
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5.  
  6. namespace BusinessModelBuilder.Models
  7. {
  8.     public class MainViewModel
  9.     {
  10.         public MainViewModel()
  11.         {
  12.            
  13.         }
  14.  
  15.         public String AppTitle { get; set; }
  16.         public String Login { get; set; }
  17.         public List<CanvasElem> CanvasElemList { get; set; }
  18.     }
  19. }
  20. _________________________________________________________________________
  21.  
  22. *** CavnasElem.cs ***
  23.  
  24. using System;
  25. using System.Collections.Generic;
  26.  
  27. namespace BusinessModelBuilder.Models
  28. {
  29.     public partial class CanvasElem
  30.     {
  31.         public string Canvaselemcontent { get; set; }
  32.         public int Canvaselemid { get; set; }
  33.         public int? Canvasid { get; set; }
  34.         public string Canvaselemfieldname { get; set; }
  35.  
  36.         public Canvas Canvas { get; set; }
  37.     }
  38. }
  39. ________________________________________________________________________________________________________
  40. *** BusinessModelCanvas.cshtml ***
  41.  
  42. @using Resources = BusinessModelBuilder.App_GlobalResources.Text
  43. <div id="canvas">
  44.     <div class="grid">
  45.         <div id="key_partners" class="template_field">
  46.             <h4>@Resources.KeyPartners</h4>
  47.             <label id="key_partners_add_new" class="add_new" onclick="addNewLabel(event)">+ @Resources.AddNew</label>
  48.         </div>
  49.         <div id="key_activities" class="template_field">
  50.             <h4>@Resources.KeyActivities</h4>
  51.             <label id="key_activities_add_new" class="add_new" onclick="addNewLabel(event)">+ @Resources.AddNew</label>
  52.         </div>
  53.         <div id="key_resources" class="template_field">
  54.             <h4>@Resources.KeyResources</h4>
  55.             <label id="key_resources_add_new" class="add_new" onclick="addNewLabel(event)">+ @Resources.AddNew</label>
  56.         </div>
  57.         <div id="value_propositions" class="template_field">
  58.             <h4>@Resources.ValuePropositions</h4>
  59.             <label id="value_propositions_add_new" class="add_new" onclick="addNewLabel(event)">+ @Resources.AddNew</label>
  60.         </div>
  61.         <div id="customer_relationships" class="template_field">
  62.             <h4>@Resources.CustomerRelationships</h4>
  63.             <label id="customer_relationships_add_new" class="add_new" onclick="addNewLabel(event)">+ @Resources.AddNew</label>
  64.         </div>
  65.         <div id="channels" class="template_field">
  66.             <h4>@Resources.Channels</h4>
  67.             <label id="channels_add_new" class="add_new" onclick="addNewLabel(event)">+ @Resources.AddNew</label>
  68.         </div>
  69.         <div id="customer_segments" class="template_field">
  70.             <h4>@Resources.CustomerSegments</h4>
  71.             <label id="customer_segments_add_new" class="add_new" onclick="addNewLabel(event)">+ @Resources.AddNew</label>
  72.         </div>
  73.         <div id="bottom_part">
  74.             <div id="cost_structure" class="template_field">
  75.                 <h4>@Resources.CostStructure</h4>
  76.                 <label id="cost_structure_add_new" class="add_new" onclick="addNewLabel(event)">+ @Resources.AddNew</label>
  77.             </div>
  78.             <div id="revenue_streams" class="template_field">
  79.                 <h4>@Resources.RevenueStreams</h4>
  80.                 <label id="revenue_streams_add_new" class="add_new" onclick="addNewLabel(event)">+ @Resources.AddNew</label>
  81.             </div>
  82.         </div>
  83.     </div>
  84. </div>
  85.  
  86. <script src="/js/jquery-3.3.1.min.js"></script>
  87. <script src="/js/signalr.js"></script>
  88.  
  89. <script type="text/javascript">
  90.     var chat = new signalR.HubConnectionBuilder().withUrl("/signalr").build();
  91.     var textAreaContainter = [];
  92.  
  93.     //local functions
  94.     function addNewLabel(event)
  95.     {
  96.         var target = event.target;
  97.         var parent = target.parentElement;
  98.  
  99.         chat.invoke("NewLabel", "@ViewData["sessionID"]", parent.id);
  100.     }
  101.  
  102.     function addNewLabelLocal(textareaid, parent, what)
  103.     {
  104.         var newLabel = document.createElement("div");
  105.         newLabel.className = "label";
  106.         newLabel.setAttribute("draggable", "true");
  107.  
  108.         var newTextArea = document.createElement("textarea");
  109.         newTextArea.id = textareaid;
  110.         newTextArea.placeholder = "@Resources.NewLabelPlaceholder";
  111.         newTextArea.innerText = what;
  112.  
  113.         $(newTextArea).on('input', function (e)
  114.         {
  115.             this.setAttribute("changed", "true");
  116.         });
  117.  
  118.         $(newTextArea).focus(function ()
  119.         {
  120.             //chat.server.lockTextArea("@ViewData["sessionID"]", $(this).attr('id'));
  121.             chat.invoke("lockTextArea", "@ViewData["sessionID"]", $(this).attr('id'));
  122.         });
  123.  
  124.         $(newTextArea).focusout(function ()
  125.         {
  126.             if ($(this).attr("changed") === "true")
  127.             {
  128.                 //chat.server.labelEdited("@ViewData["sessionID"]", $(this).attr('id'), $(this).val());
  129.                 chat.invoke("labelEdited", "@ViewData["sessionID"]", $(this).attr('id'), $(this).val());
  130.  
  131.                 $(this).attr("changed", "false");
  132.             }
  133.             //chat.server.unlockTextArea("@ViewData["sessionID"]", $(this).attr('id'));
  134.             chat.invoke("unlockTextArea", "@ViewData["sessionID"]", $(this).attr('id'));
  135.         });
  136.  
  137.         var removeButton = document.createElement("div");
  138.         removeButton.classList.add("remove_button");
  139.         removeButton.classList.add("remove_button_invisible");
  140.  
  141.         $(removeButton).click(function ()
  142.         {
  143.             //chat.server.remove("@ViewData["sessionID"]", $(newTextArea).attr('id'));
  144.             chat.invoke("remove", "@ViewData["sessionID"]", $(newTextArea).attr('id'));
  145.         });
  146.  
  147.         $(newLabel)
  148.             .mouseenter(function() {
  149.                 removeButton.classList.toggle("remove_button_invisible");
  150.             })
  151.             .mouseleave(function() {
  152.                 removeButton.classList.toggle("remove_button_invisible");
  153.             });
  154.  
  155.         textAreaContainter.push(newTextArea);
  156.  
  157.         newLabel.appendChild(newTextArea);
  158.         newLabel.appendChild(removeButton);
  159.  
  160.         parent.insertBefore(newLabel, parent.lastElementChild);
  161.  
  162.         parent.scrollTop = parent.scrollHeight - parent.clientHeight;
  163.  
  164.         //tą funkcję, szczególnie textAreaContainer raczej trzeba będzie napisać od nowa
  165.         setFocus();
  166.     }
  167.  
  168.     function setFocus() {
  169.         for (i = 0; i < textAreaContainter.length; i++) {
  170.             textAreaContainter[i].blur();
  171.         }
  172.         var lastElement = textAreaContainter.length - 1;
  173.         textAreaContainter[lastElement].focus();
  174.     }
  175.  
  176.     $("#canvas_name").on('input', function (e)
  177.     {
  178.         //chat.server.newProjectTitle("@ViewData["sessionID"]", $(this).val());
  179.         chat.invoke("newProjectTitle", "@ViewData["sessionID"]", $(this).val());
  180.     });
  181.  
  182.     //network event handlers
  183.     chat.on("addNewLabel",
  184.         function(textareaid, where, what) {
  185.             var parent = document.getElementById(where);
  186.             addNewLabelLocal(textareaid, parent, what);
  187.         }
  188.     );
  189.  
  190.     chat.on("updateTextArea",
  191.         function(textareaid, newtext) {
  192.             $("#" + textareaid).val(newtext);
  193.         }
  194.     );
  195.  
  196.     chat.on("lockTextArea",
  197.         function(textareaid) {
  198.             $("#" + textareaid).attr("readonly");
  199.         }
  200.     );
  201.  
  202.     chat.on("unlockTextArea",
  203.         function(textareaid) {
  204.             $("#" + textareaid).removeAttr("readonly");
  205.         }
  206.     );
  207.  
  208.     chat.on("remove",
  209.         function(textareaid) {
  210.             $("#" + textareaid).parent().remove();
  211.         }
  212.     );
  213.  
  214.     chat.on("setProjectTitle",
  215.         function(title) {
  216.             $("#canvas_name").val(title);
  217.         }
  218.     );
  219.  
  220.     chat.start().catch(function(err) {
  221.         return console.error(err.toString());
  222.     });
  223.    
  224.     $(function () {
  225.         //to jest oczywiście słabe, bo może się w ciągu zadanego czasu nie połączyć
  226.         setTimeout(function joinGroup() {
  227.             chat.invoke("JoinGroup", "@ViewData["sessionID"]");
  228.         }, 500);
  229.  
  230.        
  231.  
  232.         @foreach (var x in Model.CanvasElemList)  
  233.         {
  234.             <text>
  235.                 addNewLabelLocal(@x.Canvaselemid, document.getElementById("@x.Canvaselemfieldname"), "@x.Canvaselemcontent");
  236.             </text>
  237.         }
  238.     });
  239.    
  240. </script>
  241. _________________________________________________________________________________________________________________________________
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement