Пример #1
0
        public IActionResult GetPastChanges([FromQuery] string entryId, [FromQuery] string lang)
        {
            if (entryId == null || lang == null)
            {
                return(StatusCode(400, "Missing parameter(s)."));
            }
            int         idVal = EntryId.StringToId(entryId);
            string      hw, trg;
            EntryStatus status;

            SqlDict.GetEntryById(idVal, out hw, out trg, out status);
            var changes = SqlDict.GetEntryChanges(idVal);

            // Remove first item (most recent change). But first, backprop potential trg and status change
            if (changes[0].HeadBefore != null)
            {
                hw = changes[0].HeadBefore;
            }
            if (changes[0].BodyBefore != null)
            {
                trg = changes[0].BodyBefore;
            }
            if (changes[0].StatusBefore != 99)
            {
                status = (EntryStatus)changes[0].StatusBefore;
            }
            changes.RemoveAt(0);
            StringBuilder sb = new StringBuilder();

            HistoryRenderer.RenderPastChanges(sb, entryId, hw, trg, status, changes, lang);
            return(new ObjectResult(sb.ToString()));
        }
Пример #2
0
        public IActionResult GetHistoryItem([FromQuery] string entryId, [FromQuery] string lang)
        {
            if (entryId == null || lang == null)
            {
                return(StatusCode(400, "Missing parameter(s)."));
            }
            int idVal = EntryId.StringToId(entryId);

            string      hw, trg;
            EntryStatus status;

            SqlDict.GetEntryById(idVal, out hw, out trg, out status);
            StringBuilder     sb      = new StringBuilder();
            List <ChangeItem> changes = SqlDict.GetEntryChanges(idVal);
            ChangeItem        ci      = changes[0];

            ci.EntryBody   = trg;
            ci.EntryHead   = hw;
            ci.EntryStatus = status;
            HistoryRenderer.RenderItem(sb, trg, status, changes[0], lang);
            return(new ObjectResult(sb.ToString()));
        }
Пример #3
0
        public IActionResult GetEditEntryData([FromQuery] string entryId, [FromQuery] string lang)
        {
            if (entryId == null || lang == null)
            {
                return(StatusCode(400, "Missing parameter(s)."));
            }

            // The data we'll return.
            EditEntryData res = new EditEntryData();

            // Is this an authenticated user?
            int    userId;
            string userName;

            auth.CheckSession(HttpContext.Request.Headers, out userId, out userName);
            // Can she approve entries?
            if (userId != -1)
            {
                res.CanApprove = auth.CanApprove(userId);
            }

            // Retrieve entry
            int         idVal = EntryId.StringToId(entryId);
            string      hw, trg;
            EntryStatus status;

            SqlDict.GetEntryById(idVal, out hw, out trg, out status);
            CedictParser parser = new CedictParser();
            CedictEntry  entry  = parser.ParseEntry(hw + " " + trg, 0, null);

            res.Status     = status.ToString().ToLowerInvariant();
            res.HeadSimp   = entry.ChSimpl;
            res.HeadTrad   = entry.ChTrad;
            res.HeadPinyin = "";
            for (int i = 0; i != entry.PinyinCount; ++i)
            {
                if (res.HeadPinyin.Length > 0)
                {
                    res.HeadPinyin += " ";
                }
                var pys = entry.GetPinyinAt(i);
                res.HeadPinyin += pys.GetDisplayString(false);
            }
            res.TrgTxt = trg.Trim('/').Replace('/', '\n').Replace('\\', '/');

            // Entry HTML
            entry.Status = status;
            EntryRenderer er = new EntryRenderer(lang, entry, true, "mainEntry");

            er.OneLineHanziLimit = 12;
            StringBuilder sb = new StringBuilder();

            er.Render(sb, null);
            res.EntryHtml = sb.ToString();

            // Entry history
            List <ChangeItem> changes = SqlDict.GetEntryChanges(idVal);

            sb.Clear();
            HistoryRenderer.RenderEntryChanges(sb, hw, trg, status, changes, lang);
            res.HistoryHtml = sb.ToString();

            return(new ObjectResult(res));
        }