示例#1
0
文件: panel.go 项目: kego/ke
func (v *PanelView) Render() *vecty.HTML {
	var editor vecty.Component
	if v.node != nil {
		switch v.node.Type.NativeJsonType(v.Ctx) {
		case system.J_MAP:
			editor = NewMapView(v.Ctx, v.node)
		case system.J_ARRAY:
			editor = NewArrayView(v.Ctx, v.node)
		default:
			editor = NewStructView(v.Ctx, v.node)
		}
	} else if v.branch != nil {
		switch v.branch.Contents.(type) {
		case *models.DataContents:
			editor = NewPanelNavView(v.Ctx, v.branch).Contents(
				func() vecty.MarkupOrComponentOrHTML {
					return elem.UnorderedList(
						prop.Class("nav navbar-nav navbar-right"),
						elem.ListItem(
							elem.Anchor(
								vecty.Text("Add"),
								prop.Href("#"),
								event.Click(func(ev *vecty.Event) {
									addNewFile(v.Ctx, v.App, true)
								}).PreventDefault(),
							),
						),
					)
				},
			)
		case *models.TypesContents:
			editor = NewPanelNavView(v.Ctx, v.branch).Contents(
				func() vecty.MarkupOrComponentOrHTML {
					return elem.UnorderedList(
						prop.Class("nav navbar-nav navbar-right"),
						elem.ListItem(
							elem.Anchor(
								vecty.Text("Add"),
								prop.Href("#"),
								event.Click(func(ev *vecty.Event) {
									addNewFile(v.Ctx, v.App, false)
								}).PreventDefault(),
							),
						),
					)
				},
			)
		default:
			editor = NewPanelNavView(v.Ctx, v.branch)
		}
	}
	v.panel = elem.Div(
		prop.Class("content content-panel"),
		editor,
	)
	return v.panel
}
示例#2
0
文件: breadcrumbs.go 项目: kego/ke
func (v *BreadcrumbsView) Render() *vecty.HTML {
	if v.branch == nil {
		return elem.Div()
	}

	b := v.branch
	crumbs := vecty.List{}

	for b != nil {

		// copy value of b into new var because it will be used in the click
		// handler
		current := b

		if v.branch.Parent != nil && current.Parent == nil {
			break
		}

		var content vecty.List
		if current == v.branch {
			content = append(content,
				vecty.Text(
					current.Contents.Label(v.Ctx),
				),
			)
		} else {
			content = append(content,
				elem.Anchor(
					prop.Href("#"),
					vecty.Text(
						current.Contents.Label(v.Ctx),
					),
					event.Click(func(ev *vecty.Event) {
						v.App.Dispatch(&actions.BranchSelecting{Branch: current, Op: models.BranchOpClickBreadcrumb})
					}).PreventDefault(),
				),
			)
		}

		crumbs = append(
			vecty.List{
				elem.ListItem(
					vecty.ClassMap{
						"active": current == v.branch,
					},
					content,
				),
			},
			crumbs...,
		)
		b = b.Parent
	}
	return elem.OrderedList(
		prop.Class("breadcrumb"),
		crumbs,
	)
}
示例#3
0
文件: editor.go 项目: kego/ke
func (v *EditorView) errorBlock() *vecty.HTML {
	if !v.node.Invalid {
		return nil
	}

	errors := vecty.List{}
	for _, e := range v.node.Errors {
		errors = append(errors, elem.ListItem(vecty.Text(e.Description)))
	}
	return elem.Paragraph(
		prop.Class("help-block text-danger"),
		elem.UnorderedList(errors),
	)
}
示例#4
0
文件: save.go 项目: kego/ke
func (v *SaveView) Render() *vecty.HTML {
	return elem.ListItem(
		vecty.ClassMap{
			"disabled": !v.App.Files.Changed(),
		},
		elem.Anchor(
			event.Click(func(e *vecty.Event) {
				request := &shared.SaveRequest{
					Request: shared.Request{
						Path: v.App.Env.Path(),
						Hash: v.App.Env.Hash(),
					},
				}
				for n, f := range v.App.Files.All() {
					if f.Changed() {
						b, err := ke.MarshalIndent(v.Ctx, n.Value, "", "\t")
						if err != nil {
							v.App.Fail <- kerr.Wrap("MKHONBVODK", err)
						}
						request.Files = append(request.Files, shared.SaveRequestFile{
							File:  f.Filename,
							Bytes: b,
							Hash:  f.Hash,
						})
					}
				}
				response := &shared.SaveResponse{}
				done := v.App.Conn.Go(shared.Save, request, response, v.App.Fail)

				go func() {
					if err := <-done; err != nil {
						v.App.Fail <- kerr.Wrap("PVLCRRYIUD", err)
						return
					}
					v.App.Dispatcher.Dispatch(&actions.SaveFileSuccess{Response: response})
				}()

			}).PreventDefault(),
			prop.Href("#"),
			vecty.Text("Save"),
		),
	)
}
示例#5
0
文件: structfragment.go 项目: kego/ke
func nullEditor(ctx context.Context, n *node.Node, app *stores.App) *EditorView {
	add := func(e *vecty.Event) {
		types := n.Rule.PermittedTypes()
		if len(types) == 1 {
			// if only one type is compatible, don't show the
			// popup, just add it.
			app.Dispatch(&actions.Add{
				Undoer: &actions.Undoer{},
				Parent: n.Parent,
				Node:   n,
				Key:    n.Key,
				Type:   types[0],
			})
			return
		}
		app.Dispatch(&actions.OpenAddPopup{
			Parent: n.Parent,
			Node:   n,
			Types:  types,
		})
	}
	return NewEditorView(ctx, n).Icons(
		func() vecty.MarkupOrComponentOrHTML {
			return elem.Anchor(
				prop.Href("#"),
				event.Click(add).PreventDefault(),
				elem.Italic(
					prop.Class("editor-icon editor-icon-after glyphicon glyphicon-plus-sign"),
				),
			)
		},
	).Dropdown(
		func() vecty.MarkupOrComponentOrHTML {
			return elem.ListItem(
				elem.Anchor(
					prop.Href("#"),
					vecty.Text("Add"),
					event.Click(add).PreventDefault(),
				),
			)
		},
	)
}
示例#6
0
文件: viewmenu.go 项目: kego/ke
func (v *ViewMenuView) Render() *vecty.HTML {
	return elem.ListItem(
		prop.Class("dropdown"),
		elem.Anchor(
			prop.Href("#"),
			prop.Class("dropdown-toggle"),
			vecty.Data("toggle", "dropdown"),
			vecty.Text("View"),
			elem.Span(
				prop.Class("caret"),
			),
		),
		elem.UnorderedList(
			prop.Class("dropdown-menu"),
			elem.ListItem(
				vecty.ClassMap{
					"disabled": v.App.Branches.View() == models.Data,
				},
				elem.Anchor(
					event.Click(func(ev *vecty.Event) {
						v.App.Dispatch(&actions.ChangeView{View: models.Data})
					}).PreventDefault(),
					prop.Href("#"),
					vecty.Text("Data"),
				),
			),
			elem.ListItem(
				vecty.ClassMap{
					"disabled": v.App.Branches.View() == models.Types,
				},
				elem.Anchor(
					event.Click(func(ev *vecty.Event) {
						v.App.Dispatch(&actions.ChangeView{View: models.Types})
					}).PreventDefault(),
					prop.Href("#"),
					vecty.Text("Types"),
				),
			),
			elem.ListItem(
				vecty.ClassMap{
					"disabled": v.App.Branches.View() == models.Package,
				},
				elem.Anchor(
					event.Click(func(ev *vecty.Event) {
						v.App.Dispatch(&actions.ChangeView{View: models.Package})
					}).PreventDefault(),
					prop.Href("#"),
					vecty.Text("Package"),
				),
			),
			elem.ListItem(
				prop.Class("divider"),
				vecty.Property("role", "separator"),
			),
			elem.ListItem(
				elem.Anchor(
					prop.Href("#"),
					event.Click(func(ev *vecty.Event) {
						v.App.Dispatch(&actions.ToggleInfoState{})
					}).PreventDefault().StopPropagation(),
					elem.Italic(
						vecty.ClassMap{
							"dropdown-icon":       true,
							"glyphicon":           true,
							"glyphicon-check":     v.App.Misc.Info(),
							"glyphicon-unchecked": !v.App.Misc.Info(),
						},
					),
					vecty.Text("Show info"),
				),
			),
		),
	)
}
示例#7
0
文件: map.go 项目: kego/ke
func (v *MapView) Render() *vecty.HTML {
	if v.model == nil {
		return elem.Div(vecty.Text("Map (nil)"))
	}

	var info vecty.List
	if v.App.Misc.Info() {
		ir, err := v.node.Node.Rule.ItemsRule()
		if err != nil {
			v.App.Fail <- kerr.Wrap("KYTRRFBKGP", err)
			return nil
		}
		dt, err := ir.DisplayType()
		if err != nil {
			v.App.Fail <- kerr.Wrap("RRJAVDKLSI", err)
			return nil
		}
		info = append(info,
			elem.Paragraph(
				prop.Class("lead"),
				vecty.Text("type: map of "+dt),
			),
		)
	}

	return elem.Div(
		NewPanelNavView(v.Ctx, v.branch).Contents(
			func() vecty.MarkupOrComponentOrHTML {
				return elem.UnorderedList(
					prop.Class("nav navbar-nav navbar-right"),
					elem.ListItem(
						elem.Anchor(
							vecty.Text("Add"),
							prop.Href("#"),
							event.Click(func(ev *vecty.Event) {
								addCollectionItem(v.Ctx, v.App, v.model.Node)
							}).PreventDefault(),
						),
					),
					elem.ListItem(
						prop.Class("dropdown"),
						elem.Anchor(
							prop.Href("#"),
							prop.Class("dropdown-toggle"),
							vecty.Data("toggle", "dropdown"),
							vecty.Property("role", "button"),
							vecty.Property("aria-haspopup", "true"),
							vecty.Property("aria-expanded", "false"),
							vecty.Text("Options"),
							elem.Span(
								prop.Class("caret"),
							),
						),
						elem.UnorderedList(
							prop.Class("dropdown-menu"),
							elem.ListItem(
								elem.Anchor(
									prop.Href("#"),
									vecty.Text("Delete"),
									event.Click(func(e *vecty.Event) {
										v.App.Dispatch(&actions.Delete{
											Undoer: &actions.Undoer{},
											Node:   v.model.Node,
											Parent: v.model.Node.Parent,
										})
									}).PreventDefault(),
								),
							),
						),
					),
				)
			},
		),
		info,
		NewEditorListView(v.Ctx, v.model, nil, nil),
		v.errorBlock(),
	)

}
示例#8
0
文件: editor.go 项目: kego/ke
func (v *EditorView) Render() *vecty.HTML {

	var dropdownItems []vecty.MarkupOrComponentOrHTML
	dropdownItems = append(dropdownItems, v.dropdown())

	if !v.model.Node.Missing && !v.model.Node.Null {
		dropdownItems = append(dropdownItems, elem.ListItem(
			elem.Anchor(
				prop.Href("#"),
				vecty.Text("Delete"),
				event.Click(func(e *vecty.Event) {
					v.App.Dispatch(&actions.Delete{
						Undoer: &actions.Undoer{},
						Node:   v.model.Node,
						Parent: v.model.Node.Parent,
					})
				}).PreventDefault(),
			),
		))
	}

	var dropdown *vecty.HTML
	if dropdownItems != nil {
		dropdown = elem.Span(
			prop.Class("dropdown"),
			elem.Anchor(
				prop.Href("#"),
				prop.Class("dropdown-toggle"),
				vecty.Data("toggle", "dropdown"),
				vecty.Property("aria-haspopup", "true"),
				vecty.Property("aria-expanded", "true"),
				elem.Italic(
					prop.Class("editor-icon editor-icon-before glyphicon glyphicon-collapse-down"),
				),
			),
			elem.UnorderedList(
				append(dropdownItems, prop.Class("dropdown-menu"))...,
			),
		)
	}

	var handle vecty.List
	if v.model.Node.Index != -1 {
		handle = append(handle, elem.Italic(
			prop.Class("handle"),
			elem.Span(
				prop.Class("glyphicon glyphicon-option-vertical"),
			),
		))
	}

	label := elem.Label(
		prop.Class("control-label"),
		vecty.Text(
			v.model.Node.Label(v.Ctx),
		),
	)

	group := elem.Div(
		vecty.ClassMap{
			"form-group": true,
			"has-error":  v.node.Invalid,
		},
		handle,
		dropdown,
		label,
		v.icons(),
		v.controls(),
		v.helpBlock(),
		v.errorBlock(),
	)

	return group
}
示例#9
0
文件: object.go 项目: kego/ke
func (v *ObjectEditorView) Render() *vecty.HTML {

	sections := vecty.List{}
	sections = append(sections,
		views.NewPanelNavView(v.Ctx, v.branch).Contents(
			func() vecty.MarkupOrComponentOrHTML {
				return elem.UnorderedList(
					prop.Class("nav navbar-nav navbar-right"),
					elem.ListItem(
						prop.Class("dropdown"),
						elem.Anchor(
							prop.Href("#"),
							prop.Class("dropdown-toggle"),
							vecty.Data("toggle", "dropdown"),
							vecty.Property("role", "button"),
							vecty.Property("aria-haspopup", "true"),
							vecty.Property("aria-expanded", "false"),
							vecty.Text("Options"),
							elem.Span(
								prop.Class("caret"),
							),
						),
						elem.UnorderedList(
							prop.Class("dropdown-menu"),
							elem.ListItem(
								elem.Anchor(
									prop.Href("#"),
									event.Click(func(ev *vecty.Event) {
										v.App.Dispatch(&actions.ToggleSystemControls{
											Node: v.model.Node,
										})
									}).PreventDefault(),
									elem.Italic(
										vecty.ClassMap{
											"dropdown-icon":       true,
											"glyphicon":           true,
											"glyphicon-check":     v.node.ShowSystemControls,
											"glyphicon-unchecked": !v.node.ShowSystemControls,
										},
									),
									vecty.Text("System controls"),
								),
							),
							elem.ListItem(
								prop.Class("divider"),
								vecty.Property("role", "separator"),
							),
							elem.ListItem(
								elem.Anchor(
									prop.Href("#"),
									vecty.Text("Delete"),
									event.Click(func(e *vecty.Event) {
										v.App.Dispatch(&actions.Delete{
											Undoer: &actions.Undoer{},
											Node:   v.model.Node,
											Parent: v.model.Node.Parent,
										})
									}).PreventDefault(),
								),
							),
						),
					),
				)
			},
		),
	)

	d := v.model.Node.Map["description"]
	if !d.Null && !d.Missing && d.ValueString != "" {
		sections = append(sections, elem.Paragraph(
			prop.Class("lead"),
			vecty.Text(d.ValueString),
		))
	}

	if v.App.Misc.Info() {
		dt, err := v.node.Node.DisplayType(v.Ctx)
		if err != nil {
			v.App.Fail <- kerr.Wrap("KFKGCGFULR", err)
			return nil
		}
		sections = append(sections,
			elem.Paragraph(
				prop.Class("lead"),
				vecty.Text("type: "+dt),
			),
		)
	}

	if v.node.ShowSystemControls {
		sections = append(sections,
			elem.Div(
				prop.Class("well object-editor"),
				views.NewEditorListView(v.Ctx, v.model, system.NewReference("kego.io/system", "object"), []string{"id", "type"}),
			),
		)
	}

	return elem.Div(
		sections,
	)

}
示例#10
0
文件: editmenu.go 项目: kego/ke
func (v *EditMenuView) Render() *vecty.HTML {

	var undoLabel, redoLabel string
	var undoEnabled, redoEnabled bool

	if v.App.Actions.Index() <= 0 {
		undoLabel = "Undo"
	} else {
		undoEnabled = true
		undoLabel = fmt.Sprintf("Undo %s", v.App.Actions.UndoPeek().Description())
	}

	if v.App.Actions.Index() >= v.App.Actions.Count() {
		redoLabel = "Redo"
	} else {
		redoEnabled = true
		redoLabel = fmt.Sprintf("Redo %s", v.App.Actions.RedoPeek().Description())
	}

	return elem.ListItem(
		prop.Class("dropdown"),
		elem.Anchor(
			prop.Href("#"),
			prop.Class("dropdown-toggle"),
			vecty.Data("toggle", "dropdown"),
			vecty.Text("Edit"),
			elem.Span(
				prop.Class("caret"),
			),
		),
		elem.UnorderedList(
			prop.Class("dropdown-menu"),
			elem.ListItem(
				vecty.ClassMap{
					"disabled": !undoEnabled,
				},
				elem.Anchor(
					event.Click(func(e *vecty.Event) {
						action := v.App.Actions.Undo()
						if action == nil {
							return
						}
						v.App.Dispatch(action)
					}).PreventDefault().StopPropagation(),
					prop.Href("#"),
					vecty.Text(undoLabel),
				),
			),
			elem.ListItem(
				vecty.ClassMap{
					"disabled": !redoEnabled,
				},
				elem.Anchor(
					event.Click(func(e *vecty.Event) {
						action := v.App.Actions.Redo()
						if action == nil {
							return
						}
						v.App.Dispatch(action)
					}).PreventDefault().StopPropagation(),
					prop.Href("#"),
					vecty.Text(redoLabel),
				),
			),
		),
	)
}